-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
previewRelated to preview mode featuresRelated to preview mode featuresruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Summary
For pytest checks:
When argnames and argvalues are passed as keyword arguments to pytest.mark.parametrize, ruff doesn't raise PT006 where it would otherwise (for passing a list instead of a single value).
Details
Steps to reproduce the issue:
-
Create a test file
test_something.py, containing two test functions.
Note that the test functions only expect a single parametrized argument.In both cases, the
parametrize()decorator is called with a list forargnamesand a list of list forargvalues. The difference is that the first one uses positional arguments, and the second one uses keyword arguments.import pytest @pytest.mark.parametrize( ["contact_type"], [["email"], ["phone"]], ) def test_function_issue_caught_PT006(contact_type: str):... @pytest.mark.parametrize( argnames=["contact_type"], argvalues=[["email"], ["phone"]], ) def test_function_issue_uncaught_PT006(contact_type: str):...
-
Run ruff explicitly looking for the
PT006issue:$ ruff check test_something.py --select PT006
-
Expected behavior (I think, you'll confirm 😅 ):
- Ruff raises an issue
PT006with the same message for both test functions: "Use a string for the first argument".
- Ruff raises an issue
-
Actual behavior:
- Ruff raises an issue only for the first test function (the one with positional arguments):
$ ruff check test_something.py --select PT006 test_something.py:5:5: PT006 [*] Wrong type passed to first argument of `pytest.mark.parametrize`; expected `str` | 4 | @pytest.mark.parametrize( 5 | ["contact_type"], | ^^^^^^^^^^^^^^^^ PT006 6 | [["email"], ["phone"]], 7 | ) | = help: Use a string for the first argument
- Ruff raises an issue only for the first test function (the one with positional arguments):
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
previewRelated to preview mode featuresRelated to preview mode featuresruleImplementing or modifying a lint ruleImplementing or modifying a lint rule