Skip to content

Commit 80f5492

Browse files
Mark yield_fixture as deprecated (#14342)
Co-authored-by: Marco Gorelli Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ada80d5 commit 80f5492

5 files changed

Lines changed: 11 additions & 2 deletions

File tree

changelog/14342.improvement.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Marked ``yield_fixture`` as deprecated to type checkers using the ``deprecated`` decorator. Note it
2+
:ref:`has originally been deprecated <yield-fixture-deprecated>` in pytest 6.2 already.

doc/en/deprecations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ conflicts (such as :class:`pytest.File` now taking ``path`` instead of
287287
deprecation warning is now raised.
288288

289289

290+
.. _yield-fixture-deprecated:
291+
290292
The ``yield_fixture`` function/decorator
291293
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292294

src/_pytest/fixtures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from typing import TypeVar
3333
import warnings
3434

35+
from .compat import deprecated
3536
import _pytest
3637
from _pytest import nodes
3738
from _pytest._code import getfslineno
@@ -1416,6 +1417,10 @@ def fixture(
14161417
return fixture_marker
14171418

14181419

1420+
@deprecated(
1421+
"@pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.",
1422+
category=None, # We have our own runtime warning logic
1423+
)
14191424
def yield_fixture(
14201425
fixture_function=None,
14211426
*args,

src/pytest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from _pytest.fixtures import FixtureDef
2727
from _pytest.fixtures import FixtureLookupError
2828
from _pytest.fixtures import FixtureRequest
29-
from _pytest.fixtures import yield_fixture
29+
from _pytest.fixtures import yield_fixture # type: ignore[deprecated]
3030
from _pytest.freeze_support import freeze_includes
3131
from _pytest.legacypath import TempdirFactory
3232
from _pytest.legacypath import Testdir

testing/deprecated_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def pytest_runtest_call(self):
6868
def test_yield_fixture_is_deprecated() -> None:
6969
with pytest.warns(DeprecationWarning, match=r"yield_fixture is deprecated"):
7070

71-
@pytest.yield_fixture
71+
@pytest.yield_fixture # type: ignore[deprecated]
7272
def fix():
7373
assert False
7474

0 commit comments

Comments
 (0)