diff --git a/changelog/14340.improvement.rst b/changelog/14340.improvement.rst new file mode 100644 index 00000000000..0ad56a9660c --- /dev/null +++ b/changelog/14340.improvement.rst @@ -0,0 +1 @@ +Marked ``yield_fixture`` as deprecated with ``deprecated`` decorator. diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 70d3a7457f6..ad4a68b2fe5 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,9 @@ def fixture( return fixture_marker +@deprecated( + "pytest.yield_fixture is deprecated, use pytest.fixture to access configuration values instead.", +) 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