Skip to content

Commit 8f5cb46

Browse files
committed
Turn PytestDeprecationWarning into error
Fix pytest-dev#5402
1 parent be84ba8 commit 8f5cb46

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

changelog/5402.removal.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**PytestDeprecationWarning 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 ``PytestDeprecationWarning`` now generate errors
5+
instead of warning messages.
6+
7+
**The affected features will be effectively removed in pytest 5.1**, so please consult the
8+
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__
9+
section in the docs for directions on how to update existing code.
10+
11+
In the pytest ``5.0.X`` series, it is possible to change the errors back into warnings as a stop
12+
gap measure by adding this to your ``pytest.ini`` file:
13+
14+
.. code-block:: ini
15+
16+
[pytest]
17+
filterwarnings =
18+
ignore::pytest.PytestDeprecationWarning
19+
20+
But this will stop working when pytest ``5.1`` is released.
21+
22+
**If you have concerns** about the removal of a specific feature, please add a
23+
comment to `#5402 <https://github.com/pytest-dev/pytest/issues/5402>`__.

src/_pytest/warnings.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def catch_warnings_for_item(config, ihook, when, item):
7575
warnings.filterwarnings("always", category=PendingDeprecationWarning)
7676

7777
warnings.filterwarnings("error", category=pytest.RemovedInPytest4Warning)
78+
warnings.filterwarnings("error", category=pytest.PytestDeprecationWarning)
7879

7980
# filters should have this precedence: mark, cmdline options, ini
8081
# filters should be applied in the inverse order of precedence

testing/python/fixtures.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,6 @@ def __init__(self, request):
11381138
values = reprec.getfailedcollections()
11391139
assert len(values) == 1
11401140

1141-
@pytest.mark.filterwarnings("ignore::pytest.PytestDeprecationWarning")
11421141
def test_request_can_be_overridden(self, testdir):
11431142
testdir.makepyfile(
11441143
"""
@@ -1151,7 +1150,7 @@ def test_request(request):
11511150
assert request.a == 1
11521151
"""
11531152
)
1154-
reprec = testdir.inline_run()
1153+
reprec = testdir.inline_run("-Wignore::pytest.PytestDeprecationWarning")
11551154
reprec.assertoutcome(passed=1)
11561155

11571156
def test_usefixtures_marker(self, testdir):

testing/test_warnings.py

+31
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,37 @@ def test():
528528
result.stdout.fnmatch_lines(["* 1 passed in *"])
529529

530530

531+
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
532+
def test_deprecation_warning_as_error(testdir, change_default):
533+
testdir.makepyfile(
534+
"""
535+
import warnings, pytest
536+
def test():
537+
warnings.warn(pytest.PytestDeprecationWarning("some warning"))
538+
"""
539+
)
540+
if change_default == "ini":
541+
testdir.makeini(
542+
"""
543+
[pytest]
544+
filterwarnings =
545+
ignore::pytest.PytestDeprecationWarning
546+
"""
547+
)
548+
549+
args = (
550+
("-Wignore::pytest.PytestDeprecationWarning",)
551+
if change_default == "cmdline"
552+
else ()
553+
)
554+
result = testdir.runpytest(*args)
555+
if change_default is None:
556+
result.stdout.fnmatch_lines(["* 1 failed in *"])
557+
else:
558+
assert change_default in ("ini", "cmdline")
559+
result.stdout.fnmatch_lines(["* 1 passed in *"])
560+
561+
531562
class TestAssertionWarnings:
532563
@staticmethod
533564
def assert_result_warns(result, msg):

0 commit comments

Comments
 (0)