Open jamesbraza opened 1 year ago
Hi James,
Thanks for raising this. Since this plugin is based on flake8, and flake8 itself does not provide any infrastructure for automatic fixing of lint errors, this would have to be implemented from scratch, and I am not sure I have the capacity for this in the foreseeable future.
In the meantime, I would like to note two things.
1 — rules such as PT001
and PT006
are configurable, and if your project(s) have a consistent code style but it is different from our default, you can simply use non-default config values. The supported configuration options are listed in the readme.
2 — there are flake8 plugins/wrappers which are specifically designed to adopt flake8 into existing codebases. One of them is flakehell
, which introduces a concept of baseline. I do not have any firsthand experience with such tools, but they might prove useful in your case.
Also, as mentioned in https://github.com/pytest-dev/pytest/issues/10709#issuecomment-1424046196, the rules from flake8-pytest-style are available in Ruff with some autofixes, including PT001
and PT006
@jamesbraza Ruff is capable of automating these fixes.
However, it is worth noting that PT001
runs counter to the example usage in the pytest docs.
Hi @cclauss,
As mentioned in my comment above and in the docs for PT001, it is configurable: you can change the flag in your flake8 config to invert the rule behavior.
I thought pytest docs usage examples would be the default behavior and that deviations would require special settings.
I will use pytest-fixture-no-parentheses
so that my code matches the pytest docs. Thanks.
I think it would be a massive time saver if there was a tool to automatically apply some of the suggested fixes.
This could be simple for rules such as:
PT001
: turning@pytest.fixture
into@pytest.fixture()
PT006
: converting@pytest.mark.parametrize
'sargnames
into a tupleRationale
It would be useful for repos just starting out with
flake8-pytest-style
, as implementing the suggested fixes can be arduous (taking hours), especially when there's hundreds of test cases needing fixing.