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

Feature request: automatic fixing per certain rules #215

Open
jamesbraza opened this issue Feb 6, 2023 · 5 comments
Open

Feature request: automatic fixing per certain rules #215

jamesbraza opened this issue Feb 6, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@jamesbraza
Copy link

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's argnames into a tuple

Rationale

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.

@jamesbraza jamesbraza added the enhancement New feature or request label Feb 6, 2023
@m-burst
Copy link
Owner

m-burst commented Feb 7, 2023

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.

@m-burst
Copy link
Owner

m-burst commented Feb 9, 2023

Also, as mentioned in pytest-dev/pytest#10709 (comment), the rules from flake8-pytest-style are available in Ruff with some autofixes, including PT001 and PT006

@cclauss
Copy link

cclauss commented Feb 11, 2023

@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.

@m-burst
Copy link
Owner

m-burst commented Feb 13, 2023

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.

@cclauss
Copy link

cclauss commented Feb 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants