ruff: Seeking improved pytest rules, as `flake8-pytest-style` doesn't align with best practices
hi everyone,
before i evaluated ruff i wasn’t even aware of flake8-pytest-styles, as one of the pytest maintainers i’m particularly annoyed as the rules don’t reflect documented and communicated best practices and the upstream doesn’t seem likely to change those details
PT001should be reversed (drop brackets)PT004is simply incorrect - public no return value fixtures should have public names for both usage in the usefixtures maker and as dependencies in other fixturesPT005is equally incorrect - internal fixtures return values even if underscores are used - sabotage of that is not okPT006undoes the intentionally established pattern of being able to comma separate multiple names in a single stringPT009sabotages intentional usage of unittest (which is sometimes necessary)PT021sabotages well established patterns for complex fixtures that setup in phases where on needs to ensure teardown but ought not to split them into multiple smaller fixturesPT023should drop parens on marks by defaultPT024/25should warn on any mark on a fixture as no marks are supported on fixturesPT027also sabotages legitimate usage of unittest patterns
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 11
- Comments: 25 (12 by maintainers)
Commits related to this issue
- ci: remove PT rules See reson here: https://github.com/astral-sh/ruff/issues/8796#issue-2002997633 — committed to bakdata/kpops by sujuka99 3 years ago
- [`pytest`] Reverse `PT001` and `PT0023` defaults (#12106) ## Summary This patch inverts the defaults for [pytest-fixture-incorrect-parentheses-style (PT001)](https://docs.astral.sh/ruff/rules/py... — committed to astral-sh/ruff by tjkuson 2 years ago
I’ll coordinate with pytest-core to get together a official set
FYI until such time that there is an official set, for Hatch’s new
fmtcommand I’m going to by default ignore rulesPT001,PT004,PT005, andPT023, while enabling the rest.@charliermarsh FYI the latest version of flake8-pytest-style (v2.0.0), which was shipped on april 1st, inverted the defaults for PT001 and PT023 so that they now conform with pytest recommendations. Maybe ruff should push out a similar change soon?
FWIW, I have no problem with shipping better pytest rules (though I haven’t used pytest extensively so don’t feel qualified to have good opinions on the rules themselves). In practice, it may be easiest to ship them under an entirely new pytest prefix / rule set, and mark the
flake8-pytest-stylerules as deprecated, but we can make that decision later.I have a similar outlook but also I don’t enable
PT*I’m not a big fan of PT009. I want to use
unittestas it’s in the Python standard library and doesn’t require any additional packages. I’d rather write my tests usingunittestand then be free to choose a suitable driver. It seems unsatisfactory to just switch everything topytest. Happy to receive comments on this approach!Good point
It should