diff --git a/changelog/14342.improvement.rst b/changelog/14342.improvement.rst new file mode 100644 index 00000000000..5b1d8d2afe7 --- /dev/null +++ b/changelog/14342.improvement.rst @@ -0,0 +1,2 @@ +Marked ``yield_fixture`` as deprecated to type checkers using the ``deprecated`` decorator. Note it +:ref:`has originally been deprecated ` in pytest 6.2 already. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 75e7a180eb0..d10ca5a4ac6 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -283,6 +283,8 @@ conflicts (such as :class:`pytest.File` now taking ``path`` instead of deprecation warning is now raised. +.. _yield-fixture-deprecated: + The ``yield_fixture`` function/decorator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index bad6eb185a5..3e36fe9c504 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -32,6 +32,7 @@ from typing import TypeVar import warnings +from .compat import deprecated import _pytest from _pytest import nodes from _pytest._code import getfslineno @@ -1416,6 +1417,10 @@ def fixture( return fixture_marker +@deprecated( + "@pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.", + category=None, # We have our own runtime warning logic +) def yield_fixture( fixture_function=None, *args, diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index d53edb93728..a35b8965460 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -26,7 +26,7 @@ from _pytest.fixtures import FixtureDef from _pytest.fixtures import FixtureLookupError from _pytest.fixtures import FixtureRequest -from _pytest.fixtures import yield_fixture +from _pytest.fixtures import yield_fixture # type: ignore[deprecated] from _pytest.freeze_support import freeze_includes from _pytest.legacypath import TempdirFactory from _pytest.legacypath import Testdir diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index a55403b07ac..c49a6e084ce 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -68,7 +68,7 @@ def pytest_runtest_call(self): def test_yield_fixture_is_deprecated() -> None: with pytest.warns(DeprecationWarning, match=r"yield_fixture is deprecated"): - @pytest.yield_fixture + @pytest.yield_fixture # type: ignore[deprecated] def fix(): assert False