From b5c7a6d26a6eed8a16777d9fa1a91893b736095c Mon Sep 17 00:00:00 2001 From: symonk Date: Sun, 1 May 2022 16:21:59 +0100 Subject: [PATCH] #9886-deprecate-nose-support --- changelog/9886.deprecation.rst | 1 + doc/en/deprecations.rst | 14 +++++++++++++- doc/en/how-to/nose.rst | 3 ++- src/_pytest/deprecated.py | 4 ++++ src/_pytest/nose.py | 4 ++++ testing/test_nose.py | 22 ++++++++++++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 changelog/9886.deprecation.rst diff --git a/changelog/9886.deprecation.rst b/changelog/9886.deprecation.rst new file mode 100644 index 00000000000..430adc535e1 --- /dev/null +++ b/changelog/9886.deprecation.rst @@ -0,0 +1 @@ +The functionality for running tests written for `nose` has been officially deprecated. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 91944b758f9..781110e4470 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -15,9 +15,21 @@ should be used instead. Deprecated Features ------------------- + Below is a complete list of all pytest features which are considered deprecated. Using those features will issue :class:`~pytest.PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters `. + +Support for tests written for nose +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 7.1.3 + +Support for running tests written for nose is now deprecated. + +.. _node-ctor-fspath-deprecation: + + .. _instance-collector-deprecation: The ``pytest.Instance`` collector @@ -37,7 +49,7 @@ However, to keep such uses working, a dummy type has been instanted in ``pytest. and importing it emits a deprecation warning. This will be removed in pytest 8. -.. _node-ctor-fspath-deprecation: +.. _support_for_tests_written_for_nose: ``fspath`` argument for Node constructors replaced with ``pathlib.Path`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/en/how-to/nose.rst b/doc/en/how-to/nose.rst index 4bf8b06c324..8f5d3af4dc8 100644 --- a/doc/en/how-to/nose.rst +++ b/doc/en/how-to/nose.rst @@ -3,7 +3,8 @@ How to run tests written for nose ======================================= -``pytest`` has basic support for running 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``. .. _nosestyle: diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index f2d79760ae7..5066570fcca 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -22,6 +22,10 @@ "pytest_faulthandler", } +NOSE_SUPPORT = PytestRemovedIn8Warning( + "Support for nose tests is deprecated and will be removed in a future release." +) + # This can be* removed pytest 8, but it's harmless and common, so no rush to remove. # * If you're in the future: "could have been". diff --git a/src/_pytest/nose.py b/src/_pytest/nose.py index b0699d22bd8..e211988d1b4 100644 --- a/src/_pytest/nose.py +++ b/src/_pytest/nose.py @@ -1,5 +1,8 @@ """Run testsuites written for nose.""" +import warnings + from _pytest.config import hookimpl +from _pytest.deprecated import NOSE_SUPPORT from _pytest.fixtures import getfixturemarker from _pytest.nodes import Item from _pytest.python import Function @@ -38,5 +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) method() return True diff --git a/testing/test_nose.py b/testing/test_nose.py index cab5a81a2b9..7ff00718582 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -496,3 +496,25 @@ def test_it(): ) result = pytester.runpytest(p, "-p", "nose") assert result.ret == 0 + + +def test_nose_setup_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.*" + output.stdout.fnmatch_lines([message]) + output.assert_outcomes(passed=1, warnings=2)