From 47bf79763faf8669697f595528f850d8b2038787 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Wed, 22 Jul 2026 09:44:23 +0200 Subject: [PATCH] fixture: Slate yield_fixture decorator for removal in pytest 10. --- changelog/14755.deprecation.rst | 1 + doc/en/deprecations.rst | 2 +- src/_pytest/deprecated.py | 2 +- testing/deprecated_test.py | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelog/14755.deprecation.rst diff --git a/changelog/14755.deprecation.rst b/changelog/14755.deprecation.rst new file mode 100644 index 00000000000..f62a9a44219 --- /dev/null +++ b/changelog/14755.deprecation.rst @@ -0,0 +1 @@ +Schedule *yield_fixture* decorator for removal in pytest 10. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index feaeaa09736..f33835195a3 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -435,7 +435,7 @@ The ``yield_fixture`` function/decorator .. deprecated:: 6.2 -``pytest.yield_fixture`` is a deprecated alias for :func:`pytest.fixture`. +``pytest.yield_fixture`` is a deprecated alias for :func:`pytest.fixture` and will be removed in pytest 10. It has been so for a very long time, so it can be searched/replaced safely. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index f46b036affe..a17d89c660a 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -29,7 +29,7 @@ # This could have been removed pytest 8, but it's harmless and common, so no rush to remove. -YIELD_FIXTURE = PytestDeprecationWarning( +YIELD_FIXTURE = PytestRemovedIn10Warning( "@pytest.yield_fixture is deprecated.\n" "Use @pytest.fixture instead; they are the same." ) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 8eed1fb3149..3d7ca586da3 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -5,6 +5,7 @@ from _pytest.pytester import Pytester import pytest from pytest import PytestDeprecationWarning +from pytest import PytestRemovedIn10Warning @pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS)) @@ -66,7 +67,7 @@ def pytest_runtest_call(self): def test_yield_fixture_is_deprecated() -> None: - with pytest.warns(DeprecationWarning, match=r"yield_fixture is deprecated"): + with pytest.warns(PytestRemovedIn10Warning, match=r"yield_fixture is deprecated"): @pytest.yield_fixture # type: ignore[deprecated] def fix():