Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pytest convention rules PT in ruff #278

Open
nathanjmcdougall opened this issue Jul 24, 2024 · 2 comments
Open

Enable pytest convention rules PT in ruff #278

nathanjmcdougall opened this issue Jul 24, 2024 · 2 comments
Labels
.maint upkeep and maintenance of the pkg testing

Comments

@nathanjmcdougall
Copy link
Contributor

nathanjmcdougall commented Jul 24, 2024

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
Copy link
Collaborator

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)?

@isabelizimm isabelizimm added testing .maint upkeep and maintenance of the pkg labels Jul 25, 2024
@nathanjmcdougall
Copy link
Contributor Author

nathanjmcdougall commented Jul 25, 2024

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 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.maint upkeep and maintenance of the pkg testing
Projects
None yet
Development

No branches or pull requests

2 participants