From ebd0d3538e869e3ccf976ee32bd8a107311154ee Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 2 Oct 2025 11:02:37 +0300 Subject: [PATCH] Change PytestRemovedIn9Warning to error by default Per our backward compatibility policy. Fix #13779 --- changelog/13779.breaking.rst | 22 ++++++++++++++++++++++ src/_pytest/deprecated.py | 3 +-- src/_pytest/warning_types.py | 6 ++++++ src/_pytest/warnings.py | 3 +-- src/pytest/__init__.py | 2 ++ testing/acceptance_test.py | 6 +++--- testing/test_warnings.py | 3 ++- 7 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 changelog/13779.breaking.rst diff --git a/changelog/13779.breaking.rst b/changelog/13779.breaking.rst new file mode 100644 index 00000000000..f7e44c27dfa --- /dev/null +++ b/changelog/13779.breaking.rst @@ -0,0 +1,22 @@ +**PytestRemovedIn9Warning deprecation warnings are now errors by default.** + +Following our plan to remove deprecated features with as little disruption as +possible, all warnings of type ``PytestRemovedIn9Warning`` now generate errors +instead of warning messages by default. + +**The affected features will be effectively removed in pytest 9.1**, so please consult the +:ref:`deprecations` section in the docs for directions on how to update existing code. + +In the pytest ``9.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.PytestRemovedIn9Warning + +But this will stop working when pytest ``9.1`` is released. + +**If you have concerns** about the removal of a specific feature, please add a +comment to :issue:`13779`. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index a605c24e58f..24e6462506b 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -27,8 +27,7 @@ } -# This can be* removed pytest 8, but it's harmless and common, so no rush to remove. -# * If you're in the future: "could have been". +# This could have been removed pytest 8, but it's harmless and common, so no rush to remove. YIELD_FIXTURE = PytestDeprecationWarning( "@pytest.yield_fixture is deprecated.\n" "Use @pytest.fixture instead; they are the same." diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 5e78debb682..93071b4a1b2 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -56,6 +56,12 @@ class PytestRemovedIn9Warning(PytestDeprecationWarning): __module__ = "pytest" +class PytestRemovedIn10Warning(PytestDeprecationWarning): + """Warning class for features that will be removed in pytest 10.""" + + __module__ = "pytest" + + @final class PytestExperimentalApiWarning(PytestWarning, FutureWarning): """Warning category used to denote experiments in pytest. diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 806681a5020..1dbf0025a31 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -41,8 +41,7 @@ def catch_warnings_for_item( warnings.filterwarnings("always", category=DeprecationWarning) warnings.filterwarnings("always", category=PendingDeprecationWarning) - # To be enabled in pytest 9.0.0. - # warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning) + warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning) apply_warning_filters(config_filters, cmdline_filters) diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 297b524bcc2..31d56deede4 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -82,6 +82,7 @@ from _pytest.warning_types import PytestExperimentalApiWarning from _pytest.warning_types import PytestFDWarning from _pytest.warning_types import PytestRemovedIn9Warning +from _pytest.warning_types import PytestRemovedIn10Warning from _pytest.warning_types import PytestReturnNotNoneWarning from _pytest.warning_types import PytestUnhandledThreadExceptionWarning from _pytest.warning_types import PytestUnknownMarkWarning @@ -133,6 +134,7 @@ "PytestFDWarning", "PytestPluginManager", "PytestRemovedIn9Warning", + "PytestRemovedIn10Warning", "PytestReturnNotNoneWarning", "PytestUnhandledThreadExceptionWarning", "PytestUnknownMarkWarning", diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 544b2cd3f0f..b9384008483 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -1324,7 +1324,7 @@ def test_foo(async_fixture): pass """ ) - result = pytester.runpytest() + result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning") result.stdout.fnmatch_lines( [ "*== warnings summary ==*", @@ -1354,7 +1354,7 @@ def test_foo(async_fixture): ... """ ) - result = pytester.runpytest() + result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning") result.stdout.fnmatch_lines( [ "*== warnings summary ==*", @@ -1388,7 +1388,7 @@ def test_foo(async_fixture): pass """ ) - result = pytester.runpytest() + result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning") result.stdout.fnmatch_lines( [ "*== warnings summary ==*", diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 399ca586927..467753b6a6e 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -562,7 +562,8 @@ def test_invalid_regex_in_filterwarning(self, pytester: Pytester) -> None: ) -@pytest.mark.skip("not relevant until pytest 9.0") +# In 9.1, uncomment below and change RemovedIn9 -> RemovedIn10. +# @pytest.mark.skip("not relevant until pytest 10.0") @pytest.mark.parametrize("change_default", [None, "ini", "cmdline"]) def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None: """This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors.