merge upstream master and improve docs for nose support deprecations

This commit is contained in:
symonk 2022-08-07 17:58:04 +01:00
parent c3c48ff19c
commit 564b5b0e02
5 changed files with 20 additions and 11 deletions

View File

@ -23,7 +23,9 @@ Support for tests written for nose
.. deprecated:: 7.2.0 .. deprecated:: 7.2.0
Support for running tests written for nose is now deprecated. Support for running tests written for `nose <https://nose.readthedocs.io/en/latest/>`__ is now deprecated.
`nose` has been in maintenance mode-only for years, and maintaining the plugin is not trivial as it spills
over the code base (see :issue:`9886` for more details).
.. _instance-collector-deprecation: .. _instance-collector-deprecation:

View File

@ -3,8 +3,10 @@
How to run tests written for nose How to run tests written for nose
======================================= =======================================
``pytest`` has basic support for running tests written for nose_. This functionality has been ``pytest`` has basic support for running tests written for nose_.
deprecated and is likely to be removed in ``pytest 8.x``.
.. warning::
This functionality has been deprecated and is likely to be removed in ``pytest 8.x``.
.. _nosestyle: .. _nosestyle:

View File

@ -22,8 +22,10 @@ DEPRECATED_EXTERNAL_PLUGINS = {
"pytest_faulthandler", "pytest_faulthandler",
} }
NOSE_SUPPORT = PytestRemovedIn8Warning( NOSE_SUPPORT = UnformattedWarning(
"Support for nose tests is deprecated and will be removed in a future release." PytestRemovedIn8Warning,
"Support for nose tests is deprecated and will be removed in a future release.\n"
"{nodeid} is using nose method: `{nose_method}`",
) )

View File

@ -21,8 +21,8 @@ def pytest_runtest_setup(item: Item) -> None:
# see https://github.com/python/mypy/issues/2608 # see https://github.com/python/mypy/issues/2608
func = item func = item
call_optional(func.obj, "setup") call_optional(func.obj, "setup", func.nodeid)
func.addfinalizer(lambda: call_optional(func.obj, "teardown")) func.addfinalizer(lambda: call_optional(func.obj, "teardown", func.nodeid))
# NOTE: Module- and class-level fixtures are handled in python.py # NOTE: Module- and class-level fixtures are handled in python.py
# with `pluginmanager.has_plugin("nose")` checks. # with `pluginmanager.has_plugin("nose")` checks.
@ -30,7 +30,7 @@ def pytest_runtest_setup(item: Item) -> None:
# it's not straightforward. # it's not straightforward.
def call_optional(obj: object, name: str) -> bool: def call_optional(obj: object, name: str, nodeid: str) -> bool:
method = getattr(obj, name, None) method = getattr(obj, name, None)
if method is None: if method is None:
return False return False
@ -41,6 +41,6 @@ def call_optional(obj: object, name: str) -> bool:
return False return False
# If there are any problems allow the exception to raise rather than # If there are any problems allow the exception to raise rather than
# silently ignoring it. # silently ignoring it.
warnings.warn(NOSE_SUPPORT, stacklevel=2) warnings.warn(NOSE_SUPPORT.format(nodeid=nodeid, nose_method=name), stacklevel=2)
method() method()
return True return True

View File

@ -515,6 +515,9 @@ def test_nose_setup_and_teardown_is_deprecated(pytester: Pytester) -> None:
""" """
) )
output = pytester.runpytest() output = pytester.runpytest()
message = "*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.*" message = [
output.stdout.fnmatch_lines([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) output.assert_outcomes(passed=1, warnings=2)