Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14340.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Marked ``yield_fixture`` as deprecated with ``deprecated`` decorator.
4 changes: 4 additions & 0 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1416,6 +1417,9 @@ def fixture(
return fixture_marker


@deprecated(
"pytest.yield_fixture is deprecated, use pytest.fixture to access configuration values instead.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the same text as the existing runtime deprecation.

Suggested change
"pytest.yield_fixture is deprecated, use pytest.fixture to access configuration values instead.",
"@pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.",

)
def yield_fixture(
fixture_function=None,
*args,
Expand Down
2 changes: 1 addition & 1 deletion src/pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading