Move test to deprecated_test and improve message
This commit is contained in:
parent
5ee703c9b6
commit
24306f23ab
|
@ -25,7 +25,7 @@ DEPRECATED_EXTERNAL_PLUGINS = {
|
|||
NOSE_SUPPORT = UnformattedWarning(
|
||||
PytestRemovedIn8Warning,
|
||||
"Support for nose tests is deprecated and will be removed in a future release.\n"
|
||||
"{nodeid} is using nose method: `{nose_method}`",
|
||||
"{nodeid} is using nose method: `{method}` ({stage})",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -39,8 +39,12 @@ def call_optional(obj: object, name: str, nodeid: str) -> bool:
|
|||
return False
|
||||
if not callable(method):
|
||||
return False
|
||||
# Warn about deprecation of this plugin.
|
||||
method_name = getattr(method, "__name__", str(method))
|
||||
warnings.warn(
|
||||
NOSE_SUPPORT.format(nodeid=nodeid, method=method_name, stage=name), stacklevel=2
|
||||
)
|
||||
# If there are any problems allow the exception to raise rather than
|
||||
# silently ignoring it.
|
||||
warnings.warn(NOSE_SUPPORT.format(nodeid=nodeid, nose_method=name), stacklevel=2)
|
||||
method()
|
||||
return True
|
||||
|
|
|
@ -231,3 +231,31 @@ def test_importing_instance_is_deprecated(pytester: Pytester) -> None:
|
|||
match=re.escape("The pytest.Instance collector type is deprecated"),
|
||||
):
|
||||
from _pytest.python import Instance # noqa: F401
|
||||
|
||||
|
||||
def test_nose_deprecated(pytester: Pytester) -> None:
|
||||
pytest.importorskip("nose")
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from nose.tools import with_setup
|
||||
|
||||
def setup_fn_no_op():
|
||||
...
|
||||
|
||||
def teardown_fn_no_op():
|
||||
...
|
||||
|
||||
@with_setup(setup_fn_no_op, teardown_fn_no_op)
|
||||
def test_omits_warnings():
|
||||
...
|
||||
"""
|
||||
)
|
||||
output = pytester.runpytest()
|
||||
message = [
|
||||
"*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.",
|
||||
"*test_nose_deprecated.py::test_omits_warnings is using nose method: `setup_fn_no_op` (setup)",
|
||||
"*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.",
|
||||
"*test_nose_deprecated.py::test_omits_warnings is using nose method: `teardown_fn_no_op` (teardown)",
|
||||
]
|
||||
output.stdout.fnmatch_lines(message)
|
||||
output.assert_outcomes(passed=1)
|
||||
|
|
|
@ -496,28 +496,3 @@ def test_nose_setup_skipped_if_non_callable(pytester: Pytester) -> None:
|
|||
)
|
||||
result = pytester.runpytest(p, "-p", "nose")
|
||||
assert result.ret == 0
|
||||
|
||||
|
||||
def test_nose_setup_and_teardown_is_deprecated(pytester: Pytester) -> None:
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
from nose.tools import with_setup
|
||||
|
||||
def setup_fn_no_op():
|
||||
...
|
||||
|
||||
def teardown_fn_no_op():
|
||||
...
|
||||
|
||||
@with_setup(setup_fn_no_op, teardown_fn_no_op)
|
||||
def test_omits_warnings():
|
||||
...
|
||||
"""
|
||||
)
|
||||
output = pytester.runpytest()
|
||||
message = [
|
||||
"*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.",
|
||||
"*test_nose_setup_and_teardown_is_deprecated.py::test_omits_warnings is using nose method: *",
|
||||
]
|
||||
output.stdout.fnmatch_lines(message)
|
||||
output.assert_outcomes(passed=1, warnings=2)
|
||||
|
|
Loading…
Reference in New Issue