Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn PytestDeprecationWarning into error #5410

Merged
merged 1 commit into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions changelog/5402.removal.rst
@@ -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
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
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
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