Change PytestRemovedIn7Warning to error by default
Per our backward compatibility policy. Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
parent
128f29ee35
commit
a172a4141b
|
@ -0,0 +1,22 @@
|
||||||
|
**PytestRemovedIn7Warning deprecation warnings are now errors by default.**
|
||||||
|
|
||||||
|
Following our plan to remove deprecated features with as little disruption as
|
||||||
|
possible, all warnings of type ``PytestRemovedIn7Warning `` now generate errors
|
||||||
|
instead of warning messages by default.
|
||||||
|
|
||||||
|
**The affected features will be effectively removed in pytest 7.1**, so please consult the
|
||||||
|
:ref:`deprecations` 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.PytestRemovedIn7Warning
|
||||||
|
|
||||||
|
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 :issue:`9308`.
|
|
@ -49,6 +49,8 @@ def catch_warnings_for_item(
|
||||||
warnings.filterwarnings("always", category=DeprecationWarning)
|
warnings.filterwarnings("always", category=DeprecationWarning)
|
||||||
warnings.filterwarnings("always", category=PendingDeprecationWarning)
|
warnings.filterwarnings("always", category=PendingDeprecationWarning)
|
||||||
|
|
||||||
|
warnings.filterwarnings("error", category=pytest.PytestRemovedIn7Warning)
|
||||||
|
|
||||||
apply_warning_filters(config_filters, cmdline_filters)
|
apply_warning_filters(config_filters, cmdline_filters)
|
||||||
|
|
||||||
# apply filters from "filterwarnings" marks
|
# apply filters from "filterwarnings" marks
|
||||||
|
|
|
@ -831,7 +831,9 @@ class TestKeywordSelection:
|
||||||
def test_three(): assert 1
|
def test_three(): assert 1
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
reprec = pytester.inline_run("-k", "test_two:", threepass)
|
reprec = pytester.inline_run(
|
||||||
|
"-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", threepass
|
||||||
|
)
|
||||||
passed, skipped, failed = reprec.listoutcomes()
|
passed, skipped, failed = reprec.listoutcomes()
|
||||||
assert len(passed) == 2
|
assert len(passed) == 2
|
||||||
assert not failed
|
assert not failed
|
||||||
|
|
|
@ -682,7 +682,9 @@ class TestTerminalFunctional:
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = pytester.runpytest("-k", "test_two:", testpath)
|
result = pytester.runpytest(
|
||||||
|
"-Wignore::pytest.PytestRemovedIn7Warning", "-k", "test_two:", testpath
|
||||||
|
)
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"]
|
["collected 3 items / 1 deselected / 2 selected", "*test_deselected.py ..*"]
|
||||||
)
|
)
|
||||||
|
|
|
@ -518,11 +518,8 @@ class TestDeprecationWarningsByDefault:
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
|
@pytest.mark.parametrize("change_default", [None, "ini", "cmdline"])
|
||||||
@pytest.mark.skip(
|
def test_removed_in_x_warning_as_error(pytester: Pytester, change_default) -> None:
|
||||||
reason="This test should be enabled again before pytest 7.0 is released"
|
"""This ensures that PytestRemovedInXWarnings raised by pytest are turned into errors.
|
||||||
)
|
|
||||||
def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> None:
|
|
||||||
"""This ensures that PytestDeprecationWarnings raised by pytest are turned into errors.
|
|
||||||
|
|
||||||
This test should be enabled as part of each major release, and skipped again afterwards
|
This test should be enabled as part of each major release, and skipped again afterwards
|
||||||
to ensure our deprecations are turning into warnings as expected.
|
to ensure our deprecations are turning into warnings as expected.
|
||||||
|
@ -531,7 +528,7 @@ def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> Non
|
||||||
"""
|
"""
|
||||||
import warnings, pytest
|
import warnings, pytest
|
||||||
def test():
|
def test():
|
||||||
warnings.warn(pytest.PytestDeprecationWarning("some warning"))
|
warnings.warn(pytest.PytestRemovedIn7Warning("some warning"))
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
if change_default == "ini":
|
if change_default == "ini":
|
||||||
|
@ -539,12 +536,12 @@ def test_deprecation_warning_as_error(pytester: Pytester, change_default) -> Non
|
||||||
"""
|
"""
|
||||||
[pytest]
|
[pytest]
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore::pytest.PytestDeprecationWarning
|
ignore::pytest.PytestRemovedIn7Warning
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
args = (
|
args = (
|
||||||
("-Wignore::pytest.PytestDeprecationWarning",)
|
("-Wignore::pytest.PytestRemovedIn7Warning",)
|
||||||
if change_default == "cmdline"
|
if change_default == "cmdline"
|
||||||
else ()
|
else ()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue