From 71ae1d0f1e8ca0d2d652c06e6e86ff6ff252e3e6 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Tue, 14 May 2019 23:37:25 -0400 Subject: [PATCH] fix: address PytestUnknownMarkWarning As of pytest 4.5.0, a new warning is raised when the plugin doesn't register its markers. See pytest-dev/pytest#5177 The docs recommend registering custom markers: https://docs.pytest.org/en/latest/writing_plugins.html#registering-markers Signed-off-by: Mike Fiedler --- pytest_black.py | 1 + tests/test_black.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pytest_black.py b/pytest_black.py index fc678c9..567afb8 100644 --- a/pytest_black.py +++ b/pytest_black.py @@ -30,6 +30,7 @@ def pytest_configure(config): # load cached mtimes at session startup if config.option.black and hasattr(config, "cache"): config._blackmtimes = config.cache.get(HISTKEY, {}) + config.addinivalue_line("markers", "black: enable format checking with black") def pytest_unconfigure(config): diff --git a/tests/test_black.py b/tests/test_black.py index f164ecf..e01c318 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -116,3 +116,21 @@ def hello(): result = testdir.runpytest("--black") result.assert_outcomes(skipped=0, passed=1) + + +def test_pytest_deprecation_warning(testdir): + """Assert no deprecation warning is raised during test.""" + p = testdir.makepyfile( + """ + def hello(): + print("Hello, world!") + """ + ) + # replace trailing newline (stripped by testdir.makepyfile) + p = p.write(p.read() + "\n") + + result = testdir.runpytest("--black") + result.assert_outcomes(passed=1) + + out = "\n".join(result.stdout.lines) + assert "PytestUnknownMarkWarning" not in out