Skip to content

Change deprecation warnings into errors for 7.0 release #8837

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ repos:
- py>=1.8.2
- attrs>=19.2.0
- packaging
- types-atomicwrites
- types-toml
- types-pkg_resources
- repo: local
Expand Down
23 changes: 23 additions & 0 deletions changelog/7363.breaking.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 7.1**, so please consult the
`Deprecations and Removals <https://docs.pytest.org/en/stable/deprecations.html>`__
section in the docs for directions on how to update existing code.

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

.. code-block:: ini

[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning

But this will stop working when pytest ``7.1`` is released.

**If you have concerns** about the removal of a specific feature, please add a
comment to `#7363 <https://github.com/pytest-dev/pytest/issues/7363>`__.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
if not item.fspath.relto(mydir):
try:
item.path.relative_to(mydir)
except ValueError:
return
mod = item.getparent(pytest.Module).obj
if hasattr(mod, "hello"):
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def catch_warnings_for_item(
warnings.filterwarnings("always", category=DeprecationWarning)
warnings.filterwarnings("always", category=PendingDeprecationWarning)

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

apply_warning_filters(config_filters, cmdline_filters)

# apply filters from "filterwarnings" marks
Expand Down
4 changes: 3 additions & 1 deletion testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ def test_two(): assert 1
def test_three(): assert 1
"""
)
reprec = pytester.inline_run("-k", "test_two:", threepass)
reprec = pytester.inline_run(
"-k", "test_two:", threepass, "-Wignore::pytest.PytestDeprecationWarning"
)
passed, skipped, failed = reprec.listoutcomes()
assert len(passed) == 2
assert not failed
Expand Down
2 changes: 1 addition & 1 deletion testing/test_nose.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_failing():
assert False
"""
)
result = pytester.runpytest(p)
result = pytester.runpytest(p, "-Wignore::pytest.PytestDeprecationWarning")
result.assert_outcomes(skipped=1)


Expand Down
4 changes: 3 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ def test_three():
pass
"""
)
result = pytester.runpytest("-k", "test_two:", testpath)
result = pytester.runpytest(
"-k", "test_two:", testpath, "-Wignore::pytest.PytestDeprecationWarning"
)
result.stdout.fnmatch_lines(
["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"]
)
Expand Down
3 changes: 0 additions & 3 deletions testing/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,6 @@ def test_hidden_by_system(self, pytester: Pytester, monkeypatch) -> None:


@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
@pytest.mark.skip(
reason="This test should be enabled again before pytest 7.0 is released"
)
def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> None:
"""This ensures that PytestDeprecationWarnings raised by pytest are turned into errors.

Expand Down