diff --git a/AUTHORS b/AUTHORS index 49440194e5c..4a322b0a548 100644 --- a/AUTHORS +++ b/AUTHORS @@ -182,6 +182,7 @@ Russel Winder Ryan Wooden Samuel Dion-Girardeau Samuele Pedroni +Sankt Petersbug Segev Finer Serhii Mozghovyi Simon Gomizelj diff --git a/changelog/3671.bugfix.rst b/changelog/3671.bugfix.rst new file mode 100644 index 00000000000..9c61f84631c --- /dev/null +++ b/changelog/3671.bugfix.rst @@ -0,0 +1 @@ +Fix ``filterwarnings`` mark not registered diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index abd04801bde..f2f23a6e2be 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -49,6 +49,14 @@ def pytest_addoption(parser): ) +def pytest_configure(config): + config.addinivalue_line( + "markers", + "filterwarnings(warning): add a warning filter to the given test. " + "see http://pytest.org/latest/warnings.html#pytest-mark-filterwarnings ", + ) + + @contextmanager def catch_warnings_for_item(item): """ diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 15ec36600d6..a26fb459776 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -287,3 +287,18 @@ def test(): ) result = testdir.runpytest("-W", "always") result.stdout.fnmatch_lines(["*= 1 passed, 1 warnings in *"]) + + +def test_filterwarnings_mark_registration(testdir): + """Ensure filterwarnings mark is registered""" + testdir.makepyfile( + """ + import pytest + + @pytest.mark.filterwarnings('error') + def test_func(): + pass + """ + ) + result = testdir.runpytest("--strict") + assert result.ret == 0