diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT007.py b/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT007.py index 4a4d9731c0c5ba..d6a9a934e4cad4 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT007.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT007.py @@ -80,5 +80,13 @@ def test_single_list_of_lists(param): @pytest.mark.parametrize("a", [1, 2]) @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) @pytest.mark.parametrize("d", [3,]) -def test_multiple_decorators(a, b, c): +@pytest.mark.parametrize( + "d", + [("3", "4")], +) +@pytest.mark.parametrize( + "e", + [("3", "4"),], +) +def test_multiple_decorators(a, b, c, d, e): pass diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index ae9760c7e9a8de..4f7cd1c4b4dd68 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -567,7 +567,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) { // Replace `]` with `)` or `,)`. let values_end = Edit::replacement( if needs_trailing_comma { - "),".into() + ",)".into() } else { ")".into() }, diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap index 1e61a32cbac51f..1feb8b1d245d00 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap @@ -168,7 +168,7 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^^^^^^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `list` of `list` for parameter values @@ -179,8 +179,8 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), [(3, 4), (5, 6)]) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` | @@ -188,7 +188,7 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `list` of `list` for parameter values @@ -199,8 +199,8 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), ([3, 4], (5, 6))) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` | @@ -208,7 +208,7 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `list` of `list` for parameter values @@ -219,5 +219,5 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), ((3, 4), [5, 6])) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap index 3f208a2d6ce52b..2ee341b8462038 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap @@ -210,7 +210,7 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^^^^^^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `list` of `tuple` for parameter values @@ -221,5 +221,5 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), [(3, 4), (5, 6)]) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap index 55aea05664b54b..93a0b2954c4639 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap @@ -237,7 +237,7 @@ PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 80 |+@pytest.mark.parametrize("a", (1, 2)) 81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): +83 83 | @pytest.mark.parametrize( PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` | @@ -245,7 +245,7 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `tuple` of `list` for parameter values @@ -256,8 +256,8 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), ([3, 4], (5, 6))) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` | @@ -265,7 +265,7 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) | ^^^^^^ PT007 82 | @pytest.mark.parametrize("d", [3,]) -83 | def test_multiple_decorators(a, b, c): +83 | @pytest.mark.parametrize( | = help: Use `tuple` of `list` for parameter values @@ -276,8 +276,8 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 81 |+@pytest.mark.parametrize(("b", "c"), ((3, 4), [5, 6])) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` | @@ -285,8 +285,8 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 | @pytest.mark.parametrize("d", [3,]) | ^^^^ PT007 -83 | def test_multiple_decorators(a, b, c): -84 | pass +83 | @pytest.mark.parametrize( +84 | "d", | = help: Use `tuple` of `list` for parameter values @@ -296,5 +296,48 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 |-@pytest.mark.parametrize("d", [3,]) 82 |+@pytest.mark.parametrize("d", (3,)) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", +85 85 | [("3", "4")], + +PT007.py:85:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +83 | @pytest.mark.parametrize( +84 | "d", +85 | [("3", "4")], + | ^^^^^^^^^^^^ PT007 +86 | ) +87 | @pytest.mark.parametrize( + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +82 82 | @pytest.mark.parametrize("d", [3,]) +83 83 | @pytest.mark.parametrize( +84 84 | "d", +85 |- [("3", "4")], + 85 |+ (("3", "4"),), +86 86 | ) +87 87 | @pytest.mark.parametrize( +88 88 | "e", + +PT007.py:89:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +87 | @pytest.mark.parametrize( +88 | "e", +89 | [("3", "4"),], + | ^^^^^^^^^^^^^ PT007 +90 | ) +91 | def test_multiple_decorators(a, b, c, d, e): + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +86 86 | ) +87 87 | @pytest.mark.parametrize( +88 88 | "e", +89 |- [("3", "4"),], + 89 |+ (("3", "4"),), +90 90 | ) +91 91 | def test_multiple_decorators(a, b, c, d, e): +92 92 | pass diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap index d38c58b152a243..3d90a13b2eb9ca 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap @@ -279,7 +279,7 @@ PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 80 |+@pytest.mark.parametrize("a", (1, 2)) 81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 82 | @pytest.mark.parametrize("d", [3,]) -83 83 | def test_multiple_decorators(a, b, c): +83 83 | @pytest.mark.parametrize( PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` | @@ -287,8 +287,8 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 | @pytest.mark.parametrize("d", [3,]) | ^^^^ PT007 -83 | def test_multiple_decorators(a, b, c): -84 | pass +83 | @pytest.mark.parametrize( +84 | "d", | = help: Use `tuple` of `tuple` for parameter values @@ -298,5 +298,48 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect 81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) 82 |-@pytest.mark.parametrize("d", [3,]) 82 |+@pytest.mark.parametrize("d", (3,)) -83 83 | def test_multiple_decorators(a, b, c): -84 84 | pass +83 83 | @pytest.mark.parametrize( +84 84 | "d", +85 85 | [("3", "4")], + +PT007.py:85:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +83 | @pytest.mark.parametrize( +84 | "d", +85 | [("3", "4")], + | ^^^^^^^^^^^^ PT007 +86 | ) +87 | @pytest.mark.parametrize( + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +82 82 | @pytest.mark.parametrize("d", [3,]) +83 83 | @pytest.mark.parametrize( +84 84 | "d", +85 |- [("3", "4")], + 85 |+ (("3", "4"),), +86 86 | ) +87 87 | @pytest.mark.parametrize( +88 88 | "e", + +PT007.py:89:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +87 | @pytest.mark.parametrize( +88 | "e", +89 | [("3", "4"),], + | ^^^^^^^^^^^^^ PT007 +90 | ) +91 | def test_multiple_decorators(a, b, c, d, e): + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +86 86 | ) +87 87 | @pytest.mark.parametrize( +88 88 | "e", +89 |- [("3", "4"),], + 89 |+ (("3", "4"),), +90 90 | ) +91 91 | def test_multiple_decorators(a, b, c, d, e): +92 92 | pass