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 filetest_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 for argnames and a list of list for argvalues. 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 PT006 issue:
$ ruff check test_something.py --select PT006
-
Expected behavior (I think, you'll confirm 😅 ):
- Ruff raises an issue
PT006 with the same message for both test functions: "Use a string for the first argument".
-
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
Summary
For pytest checks:
When
argnamesandargvaluesare passed as keyword arguments topytest.mark.parametrize, ruff doesn't raisePT006where 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.Run ruff explicitly looking for the
PT006issue:Expected behavior (I think, you'll confirm 😅 ):
PT006with the same message for both test functions: "Use a string for the first argument".Actual behavior: