[flake8-pytest-style] Add an autofix for PT020 - #27993
Merged
Merged
Conversation
`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.
|
ntBre
reviewed
Aug 28, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thank you! This looks good to me overall, just a small versioning issue and a potential edge case in the fix safety.
Adding a fix to an existing stable rule is a breaking change under the versioning policy, so the fix is only offered when preview is enabled. Review feedback from astral-sh#27993.
The fix replaces the decorator's reference, which can span comments in
exotic cases, e.g.
@(
pytest
# comment
.yield_fixture
)
def example(): ...
Mark the fix as unsafe when comments fall in the replaced range; a
trailing comment after the decorator is unaffected and stays safe.
Review feedback from astral-sh#27993.
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`.
Pierre-Sassoulas
force-pushed
the
pt020-autofix
branch
from
August 29, 2026 06:36
8a5b6d3 to
fa2e101
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
fixtureis 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.