From 564b5b0e02835eb35a2706d6190704f0de4c4c67 Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 7 Aug 2022 17:58:04 +0100 Subject: [PATCH] merge upstream master and improve docs for nose support deprecations --- doc/en/deprecations.rst | 4 +++- doc/en/how-to/nose.rst | 6 ++++-- src/_pytest/deprecated.py | 6 ++++-- src/_pytest/nose.py | 8 ++++---- testing/test_nose.py | 7 +++++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index f659b47e8..2793dc373 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -23,7 +23,9 @@ Support for tests written for nose .. deprecated:: 7.2.0 -Support for running tests written for nose is now deprecated. +Support for running tests written for `nose `__ 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: diff --git a/doc/en/how-to/nose.rst b/doc/en/how-to/nose.rst index 8f5d3af4d..07fb65e1c 100644 --- a/doc/en/how-to/nose.rst +++ b/doc/en/how-to/nose.rst @@ -3,8 +3,10 @@ How to run tests written for nose ======================================= -``pytest`` has basic support for running tests written for nose_. This functionality has been -deprecated and is likely to be removed in ``pytest 8.x``. +``pytest`` has basic support for running tests written for nose_. + +.. warning:: + This functionality has been deprecated and is likely to be removed in ``pytest 8.x``. .. _nosestyle: diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 5066570fc..8f5f393eb 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -22,8 +22,10 @@ DEPRECATED_EXTERNAL_PLUGINS = { "pytest_faulthandler", } -NOSE_SUPPORT = PytestRemovedIn8Warning( - "Support for nose tests is deprecated and will be removed in a future release." +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}`", ) diff --git a/src/_pytest/nose.py b/src/_pytest/nose.py index e211988d1..422138e85 100644 --- a/src/_pytest/nose.py +++ b/src/_pytest/nose.py @@ -21,8 +21,8 @@ def pytest_runtest_setup(item: Item) -> None: # see https://github.com/python/mypy/issues/2608 func = item - call_optional(func.obj, "setup") - func.addfinalizer(lambda: call_optional(func.obj, "teardown")) + call_optional(func.obj, "setup", func.nodeid) + func.addfinalizer(lambda: call_optional(func.obj, "teardown", func.nodeid)) # NOTE: Module- and class-level fixtures are handled in python.py # with `pluginmanager.has_plugin("nose")` checks. @@ -30,7 +30,7 @@ def pytest_runtest_setup(item: Item) -> None: # 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) if method is None: return False @@ -41,6 +41,6 @@ def call_optional(obj: object, name: str) -> bool: return False # If there are any problems allow the exception to raise rather than # silently ignoring it. - warnings.warn(NOSE_SUPPORT, stacklevel=2) + warnings.warn(NOSE_SUPPORT.format(nodeid=nodeid, nose_method=name), stacklevel=2) method() return True diff --git a/testing/test_nose.py b/testing/test_nose.py index bad7a0f41..fe5b92d7f 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -515,6 +515,9 @@ def test_nose_setup_and_teardown_is_deprecated(pytester: Pytester) -> None: """ ) output = pytester.runpytest() - message = "*PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.*" - output.stdout.fnmatch_lines([message]) + 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)