diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0490ae968c2..363a414cf2a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -58,6 +58,7 @@ repos: - py>=1.8.2 - attrs>=19.2.0 - packaging + - types-atomicwrites - types-toml - types-pkg_resources - repo: local diff --git a/changelog/7363.breaking.rst b/changelog/7363.breaking.rst new file mode 100644 index 00000000000..76f881a04d7 --- /dev/null +++ b/changelog/7363.breaking.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 7.1**, so please consult the +`Deprecations and Removals `__ +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 `__. diff --git a/doc/en/example/assertion/global_testmodule_config/conftest.py b/doc/en/example/assertion/global_testmodule_config/conftest.py index 7cdf18cdbc1..74a19bf6ac5 100644 --- a/doc/en/example/assertion/global_testmodule_config/conftest.py +++ b/doc/en/example/assertion/global_testmodule_config/conftest.py @@ -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"): diff --git a/src/_pytest/warnings.py b/src/_pytest/warnings.py index 35eed96df58..f99199e0a72 100644 --- a/src/_pytest/warnings.py +++ b/src/_pytest/warnings.py @@ -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 diff --git a/testing/test_mark.py b/testing/test_mark.py index 77991f9e273..d5c94379183 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -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 diff --git a/testing/test_nose.py b/testing/test_nose.py index 77f79b53b3c..7de1959271f 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -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) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 3e3502b5ca9..58fd604d68b 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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 ..*"] ) diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 11678383548..9d1e9ef4de4 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -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.