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

  • PT001 should be reversed (drop brackets)
  • PT004 is simply incorrect - public no return value fixtures should have public names for both usage in the usefixtures maker and as dependencies in other fixtures
  • PT005 is equally incorrect - internal fixtures return values even if underscores are used - sabotage of that is not ok
  • PT006 undoes the intentionally established pattern of being able to comma separate multiple names in a single string
  • PT009 sabotages intentional usage of unittest (which is sometimes necessary)
  • PT021 sabotages 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 fixtures
  • PT023 should drop parens on marks by default
  • PT024/25 should warn on any mark on a fixture as no marks are supported on fixtures
  • PT027also 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

Most upvoted comments

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 fmt command I’m going to by default ignore rules PT001, PT004, PT005, and PT023, 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-style rules 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 unittest as it’s in the Python standard library and doesn’t require any additional packages. I’d rather write my tests using unittest and then be free to choose a suitable driver. It seems unsatisfactory to just switch everything to pytest. Happy to receive comments on this approach!

Good point

It should