Skip to content
Merged
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
2 changes: 2 additions & 0 deletions changelog/14342.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Marked ``yield_fixture`` as deprecated to type checkers using the ``deprecated`` decorator. Note it
:ref:`has originally been deprecated <yield-fixture-deprecated>` in pytest 6.2 already.
2 changes: 2 additions & 0 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 5 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,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,
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