Skip to content

Commit

Permalink
Turn PytestDeprecationWarning into error (#5410)
Browse files Browse the repository at this point in the history
Turn PytestDeprecationWarning into error
  • Loading branch information
nicoddemus authored Jun 6, 2019
2 parents 3656885 + 8f5cb46 commit 9f8b566
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
23 changes: 23 additions & 0 deletions changelog/5402.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**PytestDeprecationWarning are now errors by default.**

Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type ``PytestDeprecationWarning`` now generate errors
instead of warning messages.

**The affected features will be effectively removed in pytest 5.1**, so please consult the
`Deprecations and Removals <https://docs.pytest.org/en/latest/deprecations.html>`__
section in the docs for directions on how to update existing code.

In the pytest ``5.0.X`` series, it is possible to change the errors back into warnings as a stop
gap measure by adding this to your ``pytest.ini`` file:

.. code-block:: ini
[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning
But this will stop working when pytest ``5.1`` is released.

**If you have concerns** about the removal of a specific feature, please add a
comment to `#5402 <https://github.com/pytest-dev/pytest/issues/5402>`__.
1 change: 1 addition & 0 deletions src/_pytest/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def catch_warnings_for_item(config, ihook, when, item):
warnings.filterwarnings("always", category=PendingDeprecationWarning)

warnings.filterwarnings("error", category=pytest.RemovedInPytest4Warning)
warnings.filterwarnings("error", category=pytest.PytestDeprecationWarning)

# filters should have this precedence: mark, cmdline options, ini
# filters should be applied in the inverse order of precedence
Expand Down
3 changes: 1 addition & 2 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,6 @@ def __init__(self, request):
values = reprec.getfailedcollections()
assert len(values) == 1

@pytest.mark.filterwarnings("ignore::pytest.PytestDeprecationWarning")
def test_request_can_be_overridden(self, testdir):
testdir.makepyfile(
"""
Expand All @@ -1151,7 +1150,7 @@ def test_request(request):
assert request.a == 1
"""
)
reprec = testdir.inline_run()
reprec = testdir.inline_run("-Wignore::pytest.PytestDeprecationWarning")
reprec.assertoutcome(passed=1)

def test_usefixtures_marker(self, testdir):
Expand Down
31 changes: 31 additions & 0 deletions testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,37 @@ def test():
result.stdout.fnmatch_lines(["* 1 passed in *"])


@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
def test_deprecation_warning_as_error(testdir, change_default):
testdir.makepyfile(
"""
import warnings, pytest
def test():
warnings.warn(pytest.PytestDeprecationWarning("some warning"))
"""
)
if change_default == "ini":
testdir.makeini(
"""
[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning
"""
)

args = (
("-Wignore::pytest.PytestDeprecationWarning",)
if change_default == "cmdline"
else ()
)
result = testdir.runpytest(*args)
if change_default is None:
result.stdout.fnmatch_lines(["* 1 failed in *"])
else:
assert change_default in ("ini", "cmdline")
result.stdout.fnmatch_lines(["* 1 passed in *"])


class TestAssertionWarnings:
@staticmethod
def assert_result_warns(result, msg):
Expand Down

0 comments on commit 9f8b566

Please sign in to comment.