Skip to content

Commit ebd0d35

Browse files
committed
Change PytestRemovedIn9Warning to error by default
Per our backward compatibility policy. Fix #13779
1 parent a55c959 commit ebd0d35

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

changelog/13779.breaking.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**PytestRemovedIn9Warning deprecation warnings are now errors by default.**
2+
3+
Following our plan to remove deprecated features with as little disruption as
4+
possible, all warnings of type ``PytestRemovedIn9Warning`` now generate errors
5+
instead of warning messages by default.
6+
7+
**The affected features will be effectively removed in pytest 9.1**, so please consult the
8+
:ref:`deprecations` section in the docs for directions on how to update existing code.
9+
10+
In the pytest ``9.0.X`` series, it is possible to change the errors back into warnings as a
11+
stopgap measure by adding this to your ``pytest.ini`` file:
12+
13+
.. code-block:: ini
14+
15+
[pytest]
16+
filterwarnings =
17+
ignore::pytest.PytestRemovedIn9Warning
18+
19+
But this will stop working when pytest ``9.1`` is released.
20+
21+
**If you have concerns** about the removal of a specific feature, please add a
22+
comment to :issue:`13779`.

src/_pytest/deprecated.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
}
2828

2929

30-
# This can be* removed pytest 8, but it's harmless and common, so no rush to remove.
31-
# * If you're in the future: "could have been".
30+
# This could have been removed pytest 8, but it's harmless and common, so no rush to remove.
3231
YIELD_FIXTURE = PytestDeprecationWarning(
3332
"@pytest.yield_fixture is deprecated.\n"
3433
"Use @pytest.fixture instead; they are the same."

src/_pytest/warning_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class PytestRemovedIn9Warning(PytestDeprecationWarning):
5656
__module__ = "pytest"
5757

5858

59+
class PytestRemovedIn10Warning(PytestDeprecationWarning):
60+
"""Warning class for features that will be removed in pytest 10."""
61+
62+
__module__ = "pytest"
63+
64+
5965
@final
6066
class PytestExperimentalApiWarning(PytestWarning, FutureWarning):
6167
"""Warning category used to denote experiments in pytest.

src/_pytest/warnings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def catch_warnings_for_item(
4141
warnings.filterwarnings("always", category=DeprecationWarning)
4242
warnings.filterwarnings("always", category=PendingDeprecationWarning)
4343

44-
# To be enabled in pytest 9.0.0.
45-
# warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning)
44+
warnings.filterwarnings("error", category=pytest.PytestRemovedIn9Warning)
4645

4746
apply_warning_filters(config_filters, cmdline_filters)
4847

src/pytest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
from _pytest.warning_types import PytestExperimentalApiWarning
8383
from _pytest.warning_types import PytestFDWarning
8484
from _pytest.warning_types import PytestRemovedIn9Warning
85+
from _pytest.warning_types import PytestRemovedIn10Warning
8586
from _pytest.warning_types import PytestReturnNotNoneWarning
8687
from _pytest.warning_types import PytestUnhandledThreadExceptionWarning
8788
from _pytest.warning_types import PytestUnknownMarkWarning
@@ -133,6 +134,7 @@
133134
"PytestFDWarning",
134135
"PytestPluginManager",
135136
"PytestRemovedIn9Warning",
137+
"PytestRemovedIn10Warning",
136138
"PytestReturnNotNoneWarning",
137139
"PytestUnhandledThreadExceptionWarning",
138140
"PytestUnknownMarkWarning",

testing/acceptance_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ def test_foo(async_fixture):
13241324
pass
13251325
"""
13261326
)
1327-
result = pytester.runpytest()
1327+
result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning")
13281328
result.stdout.fnmatch_lines(
13291329
[
13301330
"*== warnings summary ==*",
@@ -1354,7 +1354,7 @@ def test_foo(async_fixture):
13541354
...
13551355
"""
13561356
)
1357-
result = pytester.runpytest()
1357+
result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning")
13581358
result.stdout.fnmatch_lines(
13591359
[
13601360
"*== warnings summary ==*",
@@ -1388,7 +1388,7 @@ def test_foo(async_fixture):
13881388
pass
13891389
"""
13901390
)
1391-
result = pytester.runpytest()
1391+
result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn9Warning")
13921392
result.stdout.fnmatch_lines(
13931393
[
13941394
"*== warnings summary ==*",

testing/test_warnings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ def test_invalid_regex_in_filterwarning(self, pytester: Pytester) -> None:
562562
)
563563

564564

565-
@pytest.mark.skip("not relevant until pytest 9.0")
565+
# In 9.1, uncomment below and change RemovedIn9 -> RemovedIn10.
566+
# @pytest.mark.skip("not relevant until pytest 10.0")
566567
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
567568
def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None:
568569
"""This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors.

0 commit comments

Comments
 (0)