Skip to content

Commit a4a189a

Browse files
committed
Change PytestRemovedIn8Warning to error by default
Per our backward compatibility policy.
1 parent 57d3524 commit a4a189a

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

changelog/7363.breaking.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**PytestRemovedIn8Warning 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 ``PytestRemovedIn8Warning`` now generate errors
5+
instead of warning messages by default.
6+
7+
**The affected features will be effectively removed in pytest 8.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 ``8.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.PytestRemovedIn8Warning
18+
19+
But this will stop working when pytest ``8.1`` is released.
20+
21+
**If you have concerns** about the removal of a specific feature, please add a
22+
comment to :issue:`7363`.

src/_pytest/warnings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def catch_warnings_for_item(
4949
warnings.filterwarnings("always", category=DeprecationWarning)
5050
warnings.filterwarnings("always", category=PendingDeprecationWarning)
5151

52+
warnings.filterwarnings("error", category=pytest.PytestRemovedIn8Warning)
53+
5254
apply_warning_filters(config_filters, cmdline_filters)
5355

5456
# apply filters from "filterwarnings" marks

testing/acceptance_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,6 @@ def test_usage_error_code(pytester: Pytester) -> None:
11641164
assert result.ret == ExitCode.USAGE_ERROR
11651165

11661166

1167-
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
11681167
def test_warn_on_async_function(pytester: Pytester) -> None:
11691168
# In the below we .close() the coroutine only to avoid
11701169
# "RuntimeWarning: coroutine 'test_2' was never awaited"
@@ -1181,7 +1180,7 @@ def test_3():
11811180
return coro
11821181
"""
11831182
)
1184-
result = pytester.runpytest()
1183+
result = pytester.runpytest("-Wdefault")
11851184
result.stdout.fnmatch_lines(
11861185
[
11871186
"test_async.py::test_1",
@@ -1197,7 +1196,6 @@ def test_3():
11971196
)
11981197

11991198

1200-
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
12011199
def test_warn_on_async_gen_function(pytester: Pytester) -> None:
12021200
pytester.makepyfile(
12031201
test_async="""
@@ -1209,7 +1207,7 @@ def test_3():
12091207
return test_2()
12101208
"""
12111209
)
1212-
result = pytester.runpytest()
1210+
result = pytester.runpytest("-Wdefault")
12131211
result.stdout.fnmatch_lines(
12141212
[
12151213
"test_async.py::test_1",

testing/deprecated_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_strict_option_is_deprecated(pytester: Pytester) -> None:
103103
def test_foo(): pass
104104
"""
105105
)
106-
result = pytester.runpytest("--strict")
106+
result = pytester.runpytest("--strict", "-Wdefault::pytest.PytestRemovedIn8Warning")
107107
result.stdout.fnmatch_lines(
108108
[
109109
"'unknown' not found in `markers` configuration option",
@@ -189,7 +189,7 @@ def test_skipping_msg():
189189
pytest.skip(msg="skippedmsg")
190190
"""
191191
)
192-
result = pytester.runpytest(p)
192+
result = pytester.runpytest(p, "-Wdefault::pytest.PytestRemovedIn8Warning")
193193
result.stdout.fnmatch_lines(
194194
[
195195
"*PytestRemovedIn8Warning: pytest.skip(msg=...) is now deprecated, "
@@ -208,7 +208,7 @@ def test_failing_msg():
208208
pytest.fail(msg="failedmsg")
209209
"""
210210
)
211-
result = pytester.runpytest(p)
211+
result = pytester.runpytest(p, "-Wdefault::pytest.PytestRemovedIn8Warning")
212212
result.stdout.fnmatch_lines(
213213
[
214214
"*PytestRemovedIn8Warning: pytest.fail(msg=...) is now deprecated, "
@@ -227,7 +227,7 @@ def test_exit_msg():
227227
pytest.exit(msg="exitmsg")
228228
"""
229229
)
230-
result = pytester.runpytest(p)
230+
result = pytester.runpytest(p, "-Wdefault::pytest.PytestRemovedIn8Warning")
231231
result.stdout.fnmatch_lines(
232232
[
233233
"*PytestRemovedIn8Warning: pytest.exit(msg=...) is now deprecated, "
@@ -245,7 +245,7 @@ def pytest_cmdline_preparse(config, args):
245245
246246
"""
247247
)
248-
result = pytester.runpytest()
248+
result = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn8Warning")
249249
result.stdout.fnmatch_lines(
250250
[
251251
"*PytestRemovedIn8Warning: The pytest_cmdline_preparse hook is deprecated*",
@@ -299,7 +299,7 @@ def test_omits_warnings():
299299
...
300300
"""
301301
)
302-
output = pytester.runpytest()
302+
output = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn8Warning")
303303
message = [
304304
"*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.",
305305
"*test_nose_deprecated_with_setup.py::test_omits_warnings is using nose method: `setup_fn_no_op` (setup)",
@@ -327,7 +327,7 @@ def test(self):
327327
...
328328
"""
329329
)
330-
output = pytester.runpytest()
330+
output = pytester.runpytest("-Wdefault::pytest.PytestRemovedIn8Warning")
331331
message = [
332332
"*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.",
333333
"*test_nose_deprecated_setup_teardown.py::Test::test is using nose-specific method: `setup(self)`",

testing/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ def pytest_cmdline_preparse(args):
11841184
args.append("-h")
11851185
"""
11861186
)
1187-
result = pytester.runpytest()
1187+
result = pytester.runpytest("-Wignore::pytest.PytestRemovedIn8Warning")
11881188
result.stdout.fnmatch_lines(["*pytest*", "*-h*"])
11891189

11901190

testing/test_nose.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def test_world():
2323
test_hello.teardown = lambda: values.append(2)
2424
"""
2525
)
26-
result = pytester.runpytest(p, "-p", "nose")
26+
result = pytester.runpytest(
27+
p, "-p", "nose", "-Wignore::pytest.PytestRemovedIn8Warning"
28+
)
2729
result.assert_outcomes(passed=2)
2830

2931

@@ -76,7 +78,9 @@ def test_world():
7678
7779
"""
7880
)
79-
result = pytester.runpytest(p, "-p", "nose")
81+
result = pytester.runpytest(
82+
p, "-p", "nose", "-Wignore::pytest.PytestRemovedIn8Warning"
83+
)
8084
result.assert_outcomes(passed=2)
8185

8286

@@ -100,7 +104,9 @@ def test_world():
100104
101105
"""
102106
)
103-
result = pytester.runpytest(p, "-p", "nose")
107+
result = pytester.runpytest(
108+
p, "-p", "nose", "-Wignore::pytest.PytestRemovedIn8Warning"
109+
)
104110
result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"])
105111

106112

@@ -154,7 +160,9 @@ def test_world():
154160
test_hello.teardown = my_teardown_partial
155161
"""
156162
)
157-
result = pytester.runpytest(p, "-p", "nose")
163+
result = pytester.runpytest(
164+
p, "-p", "nose", "-Wignore::pytest.PytestRemovedIn8Warning"
165+
)
158166
result.stdout.fnmatch_lines(["*2 passed*"])
159167

160168

@@ -193,7 +201,9 @@ def test_local_setup_again():
193201
assert items["setup2"] == ["up", "down", "up"]
194202
"""
195203
)
196-
result = pytester.runpytest("-p", "nose")
204+
result = pytester.runpytest(
205+
"-p", "nose", "-Wignore::pytest.PytestRemovedIn8Warning"
206+
)
197207
result.stdout.fnmatch_lines(["*4 passed*"])
198208

199209

@@ -278,7 +288,7 @@ def test_first(self):
278288
assert self.visited_cls
279289
"""
280290
)
281-
result = pytester.runpytest()
291+
result = pytester.runpytest("-Wignore::pytest.PytestRemovedIn8Warning")
282292
result.stdout.fnmatch_lines(["*1 passed*"])
283293

284294

testing/test_warnings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ def test_hidden_by_system(self, pytester: Pytester, monkeypatch) -> None:
518518
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
519519

520520

521-
@pytest.mark.skip("not relevant until pytest 8.0")
521+
# In 8.1, uncomment below and change RemovedIn8 -> RemovedIn9.
522+
# @pytest.mark.skip("not relevant until pytest 9.0")
522523
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
523524
def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None:
524525
"""This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors.

0 commit comments

Comments
 (0)