From a172a4141be59313569358c5d0077f4d326b78a4 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 14 Nov 2021 23:39:56 +0200 Subject: [PATCH] Change PytestRemovedIn7Warning to error by default Per our backward compatibility policy. Co-authored-by: Bruno Oliveira --- changelog/9308.breaking.rst | 22 ++++++++++++++++++++++ src/_pytest/warnings.py | 2 ++ testing/test_mark.py | 4 +++- testing/test_terminal.py | 4 +++- testing/test_warnings.py | 13 +++++-------- 5 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 changelog/9308.breaking.rst diff --git a/changelog/9308.breaking.rst b/changelog/9308.breaking.rst new file mode 100644 index 000000000..ca062e5a2 --- /dev/null +++ b/changelog/9308.breaking.rst @@ -0,0 +1,22 @@ +**PytestRemovedIn7Warning deprecation warnings are now errors by default.** + +Following our plan to remove deprecated features with as little disruption as +possible, all warnings of type ``PytestRemovedIn7Warning `` now generate errors +instead of warning messages by default. + +**The affected features will be effectively removed in pytest 7.1**, so please consult the +:ref:`deprecations` section in the docs for directions on how to update existing code. + +In the pytest ``7.0.X`` series, it is possible to change the errors back into warnings as a +stopgap measure by adding this to your ``pytest.ini`` file: + +.. code-block:: ini + + [pytest] + filterwarnings = + ignore::pytest.PytestRemovedIn7Warning + +But this will stop working when pytest ``7.1`` is released. + +**If you have concerns** about the removal of a specific feature, please add a +comment to :issue:`9308`. diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 4f831548d..c0c946cbd 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -49,6 +49,8 @@ def catch_warnings_for_item( warnings.filterwarnings("always", category=DeprecationWarning) warnings.filterwarnings("always", category=PendingDeprecationWarning) + warnings.filterwarnings("error", category=pytest.PytestRemovedIn7Warning) + apply_warning_filters(config_filters, cmdline_filters) # apply filters from "filterwarnings" marks diff --git a/testing/test_mark.py b/testing/test_mark.py index 19eff00f3..da67d1ea7 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -831,7 +831,9 @@ class TestKeywordSelection: def test_three(): assert 1 """ ) - reprec = pytester.inline_run("-k", "test_two:", threepass) + reprec = pytester.inline_run( + "-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", threepass + ) passed, skipped, failed = reprec.listoutcomes() assert len(passed) == 2 assert not failed diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 0f14c4d0c..32f32ff5e 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -682,7 +682,9 @@ class TestTerminalFunctional: pass """ ) - result = pytester.runpytest("-k", "test_two:", testpath) + result = pytester.runpytest( + "-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", testpath + ) result.stdout.fnmatch_lines( ["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"] ) diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 116783835..cac716680 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -518,11 +518,8 @@ class TestDeprecationWarningsByDefault: @pytest.mark.parametrize("change_default", [None, "ini", "cmdline"]) -@pytest.mark.skip( - reason="This test should be enabled again before pytest 7.0 is released" -) -def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> None: - """This ensures that PytestDeprecationWarnings raised by pytest are turned into errors. +def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None: + """This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors. This test should be enabled as part of each major release, and skipped again afterwards to ensure our deprecations are turning into warnings as expected. @@ -531,7 +528,7 @@ def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> Non """ import warnings, pytest def test(): - warnings.warn(pytest.PytestDeprecationWarning("some warning")) + warnings.warn(pytest.PytestRemovedIn7Warning("some warning")) """ ) if change_default == "ini": @@ -539,12 +536,12 @@ def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> Non """ [pytest] filterwarnings = - ignore::pytest.PytestDeprecationWarning + ignore::pytest.PytestRemovedIn7Warning """ ) args = ( - ("-Wignore::pytest.PytestDeprecationWarning",) + ("-Wignore::pytest.PytestRemovedIn7Warning",) if change_default == "cmdline" else () )