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

[false-positive][PT019] When I have a test with an underscored parameter name, it incorrectly suggests switching to usefixtures #276

Open
webknjaz opened this issue Jan 16, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@webknjaz
Copy link
Contributor

Bug report

What's wrong

I get

PT019 fixture _set without value is injected as parameter, use @pytest.mark.usefixtures instead

with

...
    @pytest.mark.parametrize(("_set", "expected"), (({"key2"}, True), ({"key"}, False)))
    def test_isdisjoint(
        self, cls: Type[MutableMultiMapping[str]], _set: Set[str], expected: bool
    ) -> None:
        ...

How it should work

PT019 shouldn't be triggered. Replacing _set with x_set works, so the plugin incorrectly assumes that there's no value provided for _set while it is, and incorrectly suggests using @pytest.mark.usefixtures, which would make it impossible to provide it with a value.

System information

  • Operating system: Gentoo/Linux
  • Python version: 3.11.5
  • flake8 version: 6.1.0
  • flake8-pytest-style version: flake8-pytest-style ~= 1.7.2
@webknjaz webknjaz added the bug Something isn't working label Jan 16, 2024
@m-burst
Copy link
Owner

m-burst commented Jan 16, 2024

Hi @webknjaz ,

I would argue that names prefixed with an underscore are designed to be unused, and to avoid clashing with builtin names I personally would suffix the name with the underscore instead of prefixing (i.e. set_ instead of _set). I understand this is opinionated, but it is consistent with rules PT004 and PT005 which check for leading underscores in fixture names.

@webknjaz
Copy link
Contributor Author

Maybe, but it's still a bug. The error is lying to my face implying that it doesn't work in runtime.

@m-burst
Copy link
Owner

m-burst commented Jan 16, 2024

I agree that the error message is misleading in this case.

In simple cases we can analyse the names configured in parametrize and avoid triggering PT019 for them. I'm not sure when I can get around to it myself, but I would gladly accept a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants