rstudio / pins-python

https://rstudio.github.io/pins-python/
MIT License
49 stars 12 forks source link

Enable `pytest` convention rules `PT` in ruff #278

Open nathanjmcdougall opened 1 month ago

nathanjmcdougall commented 1 month ago

https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt

There are many ways to do the same thing in pytest, and I have found these rules to be helpful for consistency across a codebase.

There are a few that are arguably too opinionated, in particular PT003, PT004, and PT013.

PT006 can be configured with:

[tool.ruff.lint.flake8-pytest-style]
parametrize-names-type = "csv"

for consistency with the existing codebase.

isabelizimm commented 1 month ago

Hmmm...it doesn't seem like there are many places where were are currently using complex parameterization in pytest, are you able to point to the benefits for pins (or maybe it is just to make sure it stays in compliance)?

nathanjmcdougall commented 1 month ago

Yeah I should probably have been more specific. Many PT rules are nothing to do with parameterization.

The two I see special value in for pins-python are: https://docs.astral.sh/ruff/rules/pytest-raises-too-broad/ https://docs.astral.sh/ruff/rules/pytest-raises-with-multiple-statements/ Since they force you to be a bit more rigorous in your testing.

Most of the others just keep consistency throughout a project in terms of formatting.

As you can probably tell by now, my approach with ruff is quite aggressive, anything that creates consistency makes me happy, especially when the rules have an autofix available. But that approach is not for everyone, I defer to your choice 🙇