Skip to content

PT006 issue not raised when keyword arguments are used instead of positional arguments. #15324

@caarmen

Description

@caarmen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions