Skip to content

Slate yield_fixture decorator for removal in pytest 10 - #14755

Merged
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
seifertm:yield_fixture_removal
Aug 25, 2026
Merged

RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
seifertm:yield_fixture_removal

Conversation

@seifertm

@seifertm seifertm commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Schedules the deprecated yield_fixture decorator for removal in pytest 10.

@seifertm
seifertm force-pushed the yield_fixture_removal branch from aebb7fb to f7c3caf Compare July 22, 2026 07:46
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 22, 2026
@seifertm
seifertm force-pushed the yield_fixture_removal branch 2 times, most recently from 3558bad to cd388a7 Compare July 22, 2026 07:49
@seifertm
seifertm marked this pull request as ready for review July 22, 2026 07:49
@seifertm
seifertm force-pushed the yield_fixture_removal branch from cd388a7 to 8b32b8e Compare July 22, 2026 08:32

@nicoddemus nicoddemus left a comment

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 also mention in

The ``yield_fixture`` function/decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. deprecated:: 6.2
``pytest.yield_fixture`` is a deprecated alias for :func:`pytest.fixture`.
It has been so for a very long time, so it can be searched/replaced safely.
that the decorator is slated for removal in pytest 10.0

@The-Compiler

Copy link
Copy Markdown
Member

For what it's worth, while I was +1 for removing it, our Backwards Compatibility Policy states:

trivial: APIs that trivially translate to the new mechanism and do not cause problematic changes.

We try to support those indefinitely while encouraging users to switch to newer or better mechanisms through documentation.

So I suppose this is technically going against that documented policy.

@seifertm
seifertm force-pushed the yield_fixture_removal branch from 8b32b8e to 47bf797 Compare July 24, 2026 09:56
Comment thread doc/en/deprecations.rst
@seifertm

Copy link
Copy Markdown
Contributor Author

For what it's worth, while I was +1 for removing it, our Backwards Compatibility Policy states:

trivial: APIs that trivially translate to the new mechanism and do not cause problematic changes.
We try to support those indefinitely while encouraging users to switch to newer or better mechanisms through documentation.

So I suppose this is technically going against that documented policy.

Interesting, thanks for pointing that out. I wasn't aware of this.

I do recognize that indefinitely is a very long time, though :)

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

@pytest-dev/core id like to propose replacing indefinitely in that policy with something more time constrained

This one had more than a decade

I like something like a 5 year extended deadline

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

We might create a conveniant upgrade script to make the translation bearable without following the minute details in the changelog for users. (And thus make the period even shorter)

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Is there a ruff rule?

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Indeed but without autofix; https://docs.astral.sh/ruff/rules/pytest-deprecated-yield-fixture/

For this case in particular contributing the autofix to ruff is the way to go imo. But in general if we want to reduce the deprecation period in pytest shouldn't we have our own script ?

Pierre-Sassoulas added a commit to Pierre-Sassoulas/ruff that referenced this pull request Aug 23, 2026
`pytest.yield_fixture` is a plain alias for `pytest.fixture`, so the rule
can offer the rewrite rather than only reporting it.

Following discussion in pytest-dev/pytest#14755. where
we consider deleting the function in pytest 10. It's better if an autofix exists.
I marked it as safe becuase 'fixture' is equivalent afaiu.
@RonnyPfannschmidt

Copy link
Copy Markdown
Member

why make a own script if we can document a uvx ruff .... command - heck - if we jsut get this as autofix into ruff then we can probably get this accidentially fixed

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Not all deprecations will have their own ruff rule that we can merge easily because it was already implemented in another tool (in particular new deprecation we'll introduce in the future won't). Not sure if making a ruff rule immediately when we deprecate something is going to be an easy sell to the ruff team.

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Not all thing's need a ruff rule
But anything that benefits from it would be a great offload because regarding ruff is something that most likely is automatic

So it anhillates a large part of the churn

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

based on the ruff pr and the current sentiment i'd like to get a last confirmation before merging this

@RonnyPfannschmidt
RonnyPfannschmidt merged commit d7f6190 into pytest-dev:main Aug 25, 2026
66 of 68 checks passed
Pierre-Sassoulas added a commit to Pierre-Sassoulas/ruff that referenced this pull request Aug 28, 2026
… in `PT020`

pytest-dev/pytest#14755 slated the decorator for removal in pytest 10; it
now raises `PytestRemovedIn10Warning` instead of a bare deprecation warning.
Pierre-Sassoulas added a commit to Pierre-Sassoulas/ruff that referenced this pull request Aug 29, 2026
Spell out why the alias exists and what happens to it: `pytest.fixture`
has supported `yield` since pytest 3.0, the alias has been deprecated
since 6.2, and pytest-dev/pytest#14755 slated it for removal in pytest 10,
so it now raises `PytestRemovedIn10Warning`.
ntBre pushed a commit to astral-sh/ruff that referenced this pull request Aug 31, 2026
## Summary

Following discussion in pytest-dev/pytest#14755.
where we consider deleting the function in pytest 10. It's better if an
autofix exists. I marked it as safe becuase ``fixture`` is equivalent
afaiu. (Probably better to wait for a decision in the other issue to
document it in this PR if it's removed in pytest 10)

## Test Plan

Took example with NPY003's implementation, tested alias for
yield_fixture and pytest, and various imports, used bare, with parens,
with args, with trailing comment, and inside a class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants