From e8d24ffe7612b6e45b240d8ab1ec3a267c29423f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 10 Apr 2024 14:02:52 -0400 Subject: [PATCH 1/2] Fix single-tuple conversion in pytest-parametrize-values-wrong-type --- .../fixtures/flake8_pytest_style/PT007.py | 4 + .../flake8_pytest_style/rules/parametrize.rs | 2 +- ...style__tests__PT007_list_of_lists.snap.new | 224 ++++++++++++ ...tyle__tests__PT007_list_of_tuples.snap.new | 226 ++++++++++++ ...tyle__tests__PT007_tuple_of_lists.snap.new | 323 +++++++++++++++++ ...yle__tests__PT007_tuple_of_tuples.snap.new | 325 ++++++++++++++++++ foo/bar.py | 20 ++ foo/ruff.toml | 26 ++ 8 files changed, 1149 insertions(+), 1 deletion(-) create mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new create mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new create mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new create mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new create mode 100644 foo/bar.py create mode 100644 foo/ruff.toml 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 4a4d9731c0c5b..d6ae67b5dfbd3 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,9 @@ 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,]) +@pytest.mark.parametrize( + "d", + [("3", "4")], +) def test_multiple_decorators(a, b, c): 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 ae9760c7e9a8d..4f7cd1c4b4dd6 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.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new new file mode 100644 index 0000000000000..c945dfe38451d --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new @@ -0,0 +1,224 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs +assertion_line: 303 +--- +PT007.py:4:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +4 | @pytest.mark.parametrize("param", (1, 2)) + | ^^^^^^ PT007 +5 | def test_tuple(param): +6 | ... + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +1 1 | import pytest +2 2 | +3 3 | +4 |-@pytest.mark.parametrize("param", (1, 2)) + 4 |+@pytest.mark.parametrize("param", [1, 2]) +5 5 | def test_tuple(param): +6 6 | ... +7 7 | + +PT007.py:11:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | + 9 | @pytest.mark.parametrize( +10 | ("param1", "param2"), +11 | ( + | _____^ +12 | | (1, 2), +13 | | (3, 4), +14 | | ), + | |_____^ PT007 +15 | ) +16 | def test_tuple_of_tuples(param1, param2): + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +8 8 | +9 9 | @pytest.mark.parametrize( +10 10 | ("param1", "param2"), +11 |- ( + 11 |+ [ +12 12 | (1, 2), +13 13 | (3, 4), +14 |- ), + 14 |+ ], +15 15 | ) +16 16 | def test_tuple_of_tuples(param1, param2): +17 17 | ... + +PT007.py:12:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +10 | ("param1", "param2"), +11 | ( +12 | (1, 2), + | ^^^^^^ PT007 +13 | (3, 4), +14 | ), + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +9 9 | @pytest.mark.parametrize( +10 10 | ("param1", "param2"), +11 11 | ( +12 |- (1, 2), + 12 |+ [1, 2], +13 13 | (3, 4), +14 14 | ), +15 15 | ) + +PT007.py:13:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +11 | ( +12 | (1, 2), +13 | (3, 4), + | ^^^^^^ PT007 +14 | ), +15 | ) + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +10 10 | ("param1", "param2"), +11 11 | ( +12 12 | (1, 2), +13 |- (3, 4), + 13 |+ [3, 4], +14 14 | ), +15 15 | ) +16 16 | def test_tuple_of_tuples(param1, param2): + +PT007.py:22:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +20 | @pytest.mark.parametrize( +21 | ("param1", "param2"), +22 | ( + | _____^ +23 | | [1, 2], +24 | | [3, 4], +25 | | ), + | |_____^ PT007 +26 | ) +27 | def test_tuple_of_lists(param1, param2): + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +19 19 | +20 20 | @pytest.mark.parametrize( +21 21 | ("param1", "param2"), +22 |- ( + 22 |+ [ +23 23 | [1, 2], +24 24 | [3, 4], +25 |- ), + 25 |+ ], +26 26 | ) +27 27 | def test_tuple_of_lists(param1, param2): +28 28 | ... + +PT007.py:39:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +37 | ("param1", "param2"), +38 | [ +39 | (1, 2), + | ^^^^^^ PT007 +40 | (3, 4), +41 | ], + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +36 36 | @pytest.mark.parametrize( +37 37 | ("param1", "param2"), +38 38 | [ +39 |- (1, 2), + 39 |+ [1, 2], +40 40 | (3, 4), +41 41 | ], +42 42 | ) + +PT007.py:40:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +38 | [ +39 | (1, 2), +40 | (3, 4), + | ^^^^^^ PT007 +41 | ], +42 | ) + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +37 37 | ("param1", "param2"), +38 38 | [ +39 39 | (1, 2), +40 |- (3, 4), + 40 |+ [3, 4], +41 41 | ], +42 42 | ) +43 43 | def test_list_of_tuples(param1, param2): + +PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^^^^^^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @pytest.mark.parametrize( +84 84 | "d", + +PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @pytest.mark.parametrize( +84 84 | "d", + +PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `list` of `list` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @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.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new new file mode 100644 index 0000000000000..2d6e991d202da --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new @@ -0,0 +1,226 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs +assertion_line: 303 +--- +PT007.py:4:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +4 | @pytest.mark.parametrize("param", (1, 2)) + | ^^^^^^ PT007 +5 | def test_tuple(param): +6 | ... + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +1 1 | import pytest +2 2 | +3 3 | +4 |-@pytest.mark.parametrize("param", (1, 2)) + 4 |+@pytest.mark.parametrize("param", [1, 2]) +5 5 | def test_tuple(param): +6 6 | ... +7 7 | + +PT007.py:11:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | + 9 | @pytest.mark.parametrize( +10 | ("param1", "param2"), +11 | ( + | _____^ +12 | | (1, 2), +13 | | (3, 4), +14 | | ), + | |_____^ PT007 +15 | ) +16 | def test_tuple_of_tuples(param1, param2): + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +8 8 | +9 9 | @pytest.mark.parametrize( +10 10 | ("param1", "param2"), +11 |- ( + 11 |+ [ +12 12 | (1, 2), +13 13 | (3, 4), +14 |- ), + 14 |+ ], +15 15 | ) +16 16 | def test_tuple_of_tuples(param1, param2): +17 17 | ... + +PT007.py:22:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +20 | @pytest.mark.parametrize( +21 | ("param1", "param2"), +22 | ( + | _____^ +23 | | [1, 2], +24 | | [3, 4], +25 | | ), + | |_____^ PT007 +26 | ) +27 | def test_tuple_of_lists(param1, param2): + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +19 19 | +20 20 | @pytest.mark.parametrize( +21 21 | ("param1", "param2"), +22 |- ( + 22 |+ [ +23 23 | [1, 2], +24 24 | [3, 4], +25 |- ), + 25 |+ ], +26 26 | ) +27 27 | def test_tuple_of_lists(param1, param2): +28 28 | ... + +PT007.py:23:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +21 | ("param1", "param2"), +22 | ( +23 | [1, 2], + | ^^^^^^ PT007 +24 | [3, 4], +25 | ), + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +20 20 | @pytest.mark.parametrize( +21 21 | ("param1", "param2"), +22 22 | ( +23 |- [1, 2], + 23 |+ (1, 2), +24 24 | [3, 4], +25 25 | ), +26 26 | ) + +PT007.py:24:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +22 | ( +23 | [1, 2], +24 | [3, 4], + | ^^^^^^ PT007 +25 | ), +26 | ) + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +21 21 | ("param1", "param2"), +22 22 | ( +23 23 | [1, 2], +24 |- [3, 4], + 24 |+ (3, 4), +25 25 | ), +26 26 | ) +27 27 | def test_tuple_of_lists(param1, param2): + +PT007.py:50:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +48 | ("param1", "param2"), +49 | [ +50 | [1, 2], + | ^^^^^^ PT007 +51 | [3, 4], +52 | ], + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +47 47 | @pytest.mark.parametrize( +48 48 | ("param1", "param2"), +49 49 | [ +50 |- [1, 2], + 50 |+ (1, 2), +51 51 | [3, 4], +52 52 | ], +53 53 | ) + +PT007.py:51:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +49 | [ +50 | [1, 2], +51 | [3, 4], + | ^^^^^^ PT007 +52 | ], +53 | ) + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +48 48 | ("param1", "param2"), +49 49 | [ +50 50 | [1, 2], +51 |- [3, 4], + 51 |+ (3, 4), +52 52 | ], +53 53 | ) +54 54 | def test_list_of_lists(param1, param2): + +PT007.py:61:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +59 | "param1,param2", +60 | [ +61 | [1, 2], + | ^^^^^^ PT007 +62 | [3, 4], +63 | ], + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +58 58 | @pytest.mark.parametrize( +59 59 | "param1,param2", +60 60 | [ +61 |- [1, 2], + 61 |+ (1, 2), +62 62 | [3, 4], +63 63 | ], +64 64 | ) + +PT007.py:62:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +60 | [ +61 | [1, 2], +62 | [3, 4], + | ^^^^^^ PT007 +63 | ], +64 | ) + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +59 59 | "param1,param2", +60 60 | [ +61 61 | [1, 2], +62 |- [3, 4], + 62 |+ (3, 4), +63 63 | ], +64 64 | ) +65 65 | def test_csv_name_list_of_lists(param1, param2): + +PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^^^^^^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `list` of `tuple` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @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.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new new file mode 100644 index 0000000000000..49c526e181b5e --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new @@ -0,0 +1,323 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs +assertion_line: 303 +--- +PT007.py:12:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +10 | ("param1", "param2"), +11 | ( +12 | (1, 2), + | ^^^^^^ PT007 +13 | (3, 4), +14 | ), + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +9 9 | @pytest.mark.parametrize( +10 10 | ("param1", "param2"), +11 11 | ( +12 |- (1, 2), + 12 |+ [1, 2], +13 13 | (3, 4), +14 14 | ), +15 15 | ) + +PT007.py:13:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +11 | ( +12 | (1, 2), +13 | (3, 4), + | ^^^^^^ PT007 +14 | ), +15 | ) + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +10 10 | ("param1", "param2"), +11 11 | ( +12 12 | (1, 2), +13 |- (3, 4), + 13 |+ [3, 4], +14 14 | ), +15 15 | ) +16 16 | def test_tuple_of_tuples(param1, param2): + +PT007.py:31:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +31 | @pytest.mark.parametrize("param", [1, 2]) + | ^^^^^^ PT007 +32 | def test_list(param): +33 | ... + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +28 28 | ... +29 29 | +30 30 | +31 |-@pytest.mark.parametrize("param", [1, 2]) + 31 |+@pytest.mark.parametrize("param", (1, 2)) +32 32 | def test_list(param): +33 33 | ... +34 34 | + +PT007.py:38:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +36 | @pytest.mark.parametrize( +37 | ("param1", "param2"), +38 | [ + | _____^ +39 | | (1, 2), +40 | | (3, 4), +41 | | ], + | |_____^ PT007 +42 | ) +43 | def test_list_of_tuples(param1, param2): + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +35 35 | +36 36 | @pytest.mark.parametrize( +37 37 | ("param1", "param2"), +38 |- [ + 38 |+ ( +39 39 | (1, 2), +40 40 | (3, 4), +41 |- ], + 41 |+ ), +42 42 | ) +43 43 | def test_list_of_tuples(param1, param2): +44 44 | ... + +PT007.py:39:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +37 | ("param1", "param2"), +38 | [ +39 | (1, 2), + | ^^^^^^ PT007 +40 | (3, 4), +41 | ], + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +36 36 | @pytest.mark.parametrize( +37 37 | ("param1", "param2"), +38 38 | [ +39 |- (1, 2), + 39 |+ [1, 2], +40 40 | (3, 4), +41 41 | ], +42 42 | ) + +PT007.py:40:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +38 | [ +39 | (1, 2), +40 | (3, 4), + | ^^^^^^ PT007 +41 | ], +42 | ) + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +37 37 | ("param1", "param2"), +38 38 | [ +39 39 | (1, 2), +40 |- (3, 4), + 40 |+ [3, 4], +41 41 | ], +42 42 | ) +43 43 | def test_list_of_tuples(param1, param2): + +PT007.py:49:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +47 | @pytest.mark.parametrize( +48 | ("param1", "param2"), +49 | [ + | _____^ +50 | | [1, 2], +51 | | [3, 4], +52 | | ], + | |_____^ PT007 +53 | ) +54 | def test_list_of_lists(param1, param2): + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +46 46 | +47 47 | @pytest.mark.parametrize( +48 48 | ("param1", "param2"), +49 |- [ + 49 |+ ( +50 50 | [1, 2], +51 51 | [3, 4], +52 |- ], + 52 |+ ), +53 53 | ) +54 54 | def test_list_of_lists(param1, param2): +55 55 | ... + +PT007.py:60:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +58 | @pytest.mark.parametrize( +59 | "param1,param2", +60 | [ + | _____^ +61 | | [1, 2], +62 | | [3, 4], +63 | | ], + | |_____^ PT007 +64 | ) +65 | def test_csv_name_list_of_lists(param1, param2): + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +57 57 | +58 58 | @pytest.mark.parametrize( +59 59 | "param1,param2", +60 |- [ + 60 |+ ( +61 61 | [1, 2], +62 62 | [3, 4], +63 |- ], + 63 |+ ), +64 64 | ) +65 65 | def test_csv_name_list_of_lists(param1, param2): +66 66 | ... + +PT007.py:71:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +69 | @pytest.mark.parametrize( +70 | "param", +71 | [ + | _____^ +72 | | [1, 2], +73 | | [3, 4], +74 | | ], + | |_____^ PT007 +75 | ) +76 | def test_single_list_of_lists(param): + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +68 68 | +69 69 | @pytest.mark.parametrize( +70 70 | "param", +71 |- [ + 71 |+ ( +72 72 | [1, 2], +73 73 | [3, 4], +74 |- ], + 74 |+ ), +75 75 | ) +76 76 | def test_single_list_of_lists(param): +77 77 | ... + +PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) + | ^^^^^^ PT007 +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | @pytest.mark.parametrize("d", [3,]) + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +77 77 | ... +78 78 | +79 79 | +80 |-@pytest.mark.parametrize("a", [1, 2]) + 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 | @pytest.mark.parametrize( + +PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @pytest.mark.parametrize( +84 84 | "d", + +PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +82 | @pytest.mark.parametrize("d", [3,]) +83 | @pytest.mark.parametrize( + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +78 78 | +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @pytest.mark.parametrize( +84 84 | "d", + +PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | @pytest.mark.parametrize("d", [3,]) + | ^^^^ PT007 +83 | @pytest.mark.parametrize( +84 | "d", + | + = help: Use `tuple` of `list` for parameter values + +ℹ Unsafe fix +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @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 | def test_multiple_decorators(a, b, c): + | + = 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 | def test_multiple_decorators(a, b, c): +88 88 | 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.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new new file mode 100644 index 0000000000000..c9fff8ccbc99b --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new @@ -0,0 +1,325 @@ +--- +source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs +assertion_line: 303 +--- +PT007.py:23:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +21 | ("param1", "param2"), +22 | ( +23 | [1, 2], + | ^^^^^^ PT007 +24 | [3, 4], +25 | ), + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +20 20 | @pytest.mark.parametrize( +21 21 | ("param1", "param2"), +22 22 | ( +23 |- [1, 2], + 23 |+ (1, 2), +24 24 | [3, 4], +25 25 | ), +26 26 | ) + +PT007.py:24:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +22 | ( +23 | [1, 2], +24 | [3, 4], + | ^^^^^^ PT007 +25 | ), +26 | ) + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +21 21 | ("param1", "param2"), +22 22 | ( +23 23 | [1, 2], +24 |- [3, 4], + 24 |+ (3, 4), +25 25 | ), +26 26 | ) +27 27 | def test_tuple_of_lists(param1, param2): + +PT007.py:31:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +31 | @pytest.mark.parametrize("param", [1, 2]) + | ^^^^^^ PT007 +32 | def test_list(param): +33 | ... + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +28 28 | ... +29 29 | +30 30 | +31 |-@pytest.mark.parametrize("param", [1, 2]) + 31 |+@pytest.mark.parametrize("param", (1, 2)) +32 32 | def test_list(param): +33 33 | ... +34 34 | + +PT007.py:38:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +36 | @pytest.mark.parametrize( +37 | ("param1", "param2"), +38 | [ + | _____^ +39 | | (1, 2), +40 | | (3, 4), +41 | | ], + | |_____^ PT007 +42 | ) +43 | def test_list_of_tuples(param1, param2): + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +35 35 | +36 36 | @pytest.mark.parametrize( +37 37 | ("param1", "param2"), +38 |- [ + 38 |+ ( +39 39 | (1, 2), +40 40 | (3, 4), +41 |- ], + 41 |+ ), +42 42 | ) +43 43 | def test_list_of_tuples(param1, param2): +44 44 | ... + +PT007.py:49:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +47 | @pytest.mark.parametrize( +48 | ("param1", "param2"), +49 | [ + | _____^ +50 | | [1, 2], +51 | | [3, 4], +52 | | ], + | |_____^ PT007 +53 | ) +54 | def test_list_of_lists(param1, param2): + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +46 46 | +47 47 | @pytest.mark.parametrize( +48 48 | ("param1", "param2"), +49 |- [ + 49 |+ ( +50 50 | [1, 2], +51 51 | [3, 4], +52 |- ], + 52 |+ ), +53 53 | ) +54 54 | def test_list_of_lists(param1, param2): +55 55 | ... + +PT007.py:50:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +48 | ("param1", "param2"), +49 | [ +50 | [1, 2], + | ^^^^^^ PT007 +51 | [3, 4], +52 | ], + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +47 47 | @pytest.mark.parametrize( +48 48 | ("param1", "param2"), +49 49 | [ +50 |- [1, 2], + 50 |+ (1, 2), +51 51 | [3, 4], +52 52 | ], +53 53 | ) + +PT007.py:51:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +49 | [ +50 | [1, 2], +51 | [3, 4], + | ^^^^^^ PT007 +52 | ], +53 | ) + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +48 48 | ("param1", "param2"), +49 49 | [ +50 50 | [1, 2], +51 |- [3, 4], + 51 |+ (3, 4), +52 52 | ], +53 53 | ) +54 54 | def test_list_of_lists(param1, param2): + +PT007.py:60:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +58 | @pytest.mark.parametrize( +59 | "param1,param2", +60 | [ + | _____^ +61 | | [1, 2], +62 | | [3, 4], +63 | | ], + | |_____^ PT007 +64 | ) +65 | def test_csv_name_list_of_lists(param1, param2): + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +57 57 | +58 58 | @pytest.mark.parametrize( +59 59 | "param1,param2", +60 |- [ + 60 |+ ( +61 61 | [1, 2], +62 62 | [3, 4], +63 |- ], + 63 |+ ), +64 64 | ) +65 65 | def test_csv_name_list_of_lists(param1, param2): +66 66 | ... + +PT007.py:61:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +59 | "param1,param2", +60 | [ +61 | [1, 2], + | ^^^^^^ PT007 +62 | [3, 4], +63 | ], + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +58 58 | @pytest.mark.parametrize( +59 59 | "param1,param2", +60 60 | [ +61 |- [1, 2], + 61 |+ (1, 2), +62 62 | [3, 4], +63 63 | ], +64 64 | ) + +PT007.py:62:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +60 | [ +61 | [1, 2], +62 | [3, 4], + | ^^^^^^ PT007 +63 | ], +64 | ) + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +59 59 | "param1,param2", +60 60 | [ +61 61 | [1, 2], +62 |- [3, 4], + 62 |+ (3, 4), +63 63 | ], +64 64 | ) +65 65 | def test_csv_name_list_of_lists(param1, param2): + +PT007.py:71:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +69 | @pytest.mark.parametrize( +70 | "param", +71 | [ + | _____^ +72 | | [1, 2], +73 | | [3, 4], +74 | | ], + | |_____^ PT007 +75 | ) +76 | def test_single_list_of_lists(param): + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +68 68 | +69 69 | @pytest.mark.parametrize( +70 70 | "param", +71 |- [ + 71 |+ ( +72 72 | [1, 2], +73 73 | [3, 4], +74 |- ], + 74 |+ ), +75 75 | ) +76 76 | def test_single_list_of_lists(param): +77 77 | ... + +PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +80 | @pytest.mark.parametrize("a", [1, 2]) + | ^^^^^^ PT007 +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | @pytest.mark.parametrize("d", [3,]) + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +77 77 | ... +78 78 | +79 79 | +80 |-@pytest.mark.parametrize("a", [1, 2]) + 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 | @pytest.mark.parametrize( + +PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +80 | @pytest.mark.parametrize("a", [1, 2]) +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | @pytest.mark.parametrize("d", [3,]) + | ^^^^ PT007 +83 | @pytest.mark.parametrize( +84 | "d", + | + = help: Use `tuple` of `tuple` for parameter values + +ℹ Unsafe fix +79 79 | +80 80 | @pytest.mark.parametrize("a", [1, 2]) +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 | @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 | def test_multiple_decorators(a, b, c): + | + = 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 | def test_multiple_decorators(a, b, c): +88 88 | pass diff --git a/foo/bar.py b/foo/bar.py new file mode 100644 index 0000000000000..556ad16d4c3b6 --- /dev/null +++ b/foo/bar.py @@ -0,0 +1,20 @@ +import pytest +from pytest_mock import MockFixture + +from module.sub import ( + get_value, +) + + +@pytest.fixture +def mock_check_output(mocker: MockFixture, output: bytes): + return mocker.patch("subprocess.check_output", return_value=output) + + +@pytest.mark.parametrize( + "output, expected_result", + [(b"apple", "apple")], +) +def test_get_value(mock_check_output, expected_result): + assert get_value() == expected_result + mock_check_output.assert_called_once() diff --git a/foo/ruff.toml b/foo/ruff.toml new file mode 100644 index 0000000000000..b15068d3f8f37 --- /dev/null +++ b/foo/ruff.toml @@ -0,0 +1,26 @@ +line-length = 120 + +target-version = "py38" + +lint.extend-select = [ + "W", # whitespace + "I", # imports + + # pytest + "PT001", # pytest-fixture-incorrect-parentheses-style + "PT006", # pytest-parametrize-names-wrong-type + "PT007", # pytest-parametrize-values-wrong-type + "PT025", # pytest-erroneous-use-fixtures-on-fixture + "PT026", # pytest-use-fixtures-without-parameters +] + +[ lint.isort ] + +known-first-party = ["module"] + +[ lint.flake8-pytest-style ] + +fixture-parentheses = false +parametrize-names-type = "csv" +parametrize-values-row-type = "tuple" +parametrize-values-type = "tuple" From 089270be06587f5568c73aca5d7a62e772cd2f79 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 10 Apr 2024 14:03:00 -0400 Subject: [PATCH 2/2] Remove test files --- .../fixtures/flake8_pytest_style/PT007.py | 6 +- ...est_style__tests__PT007_list_of_lists.snap | 18 +- ...style__tests__PT007_list_of_lists.snap.new | 224 ------------ ...st_style__tests__PT007_list_of_tuples.snap | 6 +- ...tyle__tests__PT007_list_of_tuples.snap.new | 226 ------------ ...st_style__tests__PT007_tuple_of_lists.snap | 65 +++- ...tyle__tests__PT007_tuple_of_lists.snap.new | 323 ----------------- ...t_style__tests__PT007_tuple_of_tuples.snap | 53 ++- ...yle__tests__PT007_tuple_of_tuples.snap.new | 325 ------------------ foo/bar.py | 20 -- foo/ruff.toml | 26 -- 11 files changed, 119 insertions(+), 1173 deletions(-) delete mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new delete mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new delete mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new delete mode 100644 crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new delete mode 100644 foo/bar.py delete mode 100644 foo/ruff.toml 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 d6ae67b5dfbd3..d6a9a934e4cad 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 @@ -84,5 +84,9 @@ def test_single_list_of_lists(param): "d", [("3", "4")], ) -def test_multiple_decorators(a, b, c): +@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/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 1e61a32cbac51..1feb8b1d245d0 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_lists.snap.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new deleted file mode 100644 index c945dfe38451d..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap.new +++ /dev/null @@ -1,224 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs -assertion_line: 303 ---- -PT007.py:4:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -4 | @pytest.mark.parametrize("param", (1, 2)) - | ^^^^^^ PT007 -5 | def test_tuple(param): -6 | ... - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -1 1 | import pytest -2 2 | -3 3 | -4 |-@pytest.mark.parametrize("param", (1, 2)) - 4 |+@pytest.mark.parametrize("param", [1, 2]) -5 5 | def test_tuple(param): -6 6 | ... -7 7 | - -PT007.py:11:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | - 9 | @pytest.mark.parametrize( -10 | ("param1", "param2"), -11 | ( - | _____^ -12 | | (1, 2), -13 | | (3, 4), -14 | | ), - | |_____^ PT007 -15 | ) -16 | def test_tuple_of_tuples(param1, param2): - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -8 8 | -9 9 | @pytest.mark.parametrize( -10 10 | ("param1", "param2"), -11 |- ( - 11 |+ [ -12 12 | (1, 2), -13 13 | (3, 4), -14 |- ), - 14 |+ ], -15 15 | ) -16 16 | def test_tuple_of_tuples(param1, param2): -17 17 | ... - -PT007.py:12:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -10 | ("param1", "param2"), -11 | ( -12 | (1, 2), - | ^^^^^^ PT007 -13 | (3, 4), -14 | ), - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -9 9 | @pytest.mark.parametrize( -10 10 | ("param1", "param2"), -11 11 | ( -12 |- (1, 2), - 12 |+ [1, 2], -13 13 | (3, 4), -14 14 | ), -15 15 | ) - -PT007.py:13:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -11 | ( -12 | (1, 2), -13 | (3, 4), - | ^^^^^^ PT007 -14 | ), -15 | ) - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -10 10 | ("param1", "param2"), -11 11 | ( -12 12 | (1, 2), -13 |- (3, 4), - 13 |+ [3, 4], -14 14 | ), -15 15 | ) -16 16 | def test_tuple_of_tuples(param1, param2): - -PT007.py:22:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -20 | @pytest.mark.parametrize( -21 | ("param1", "param2"), -22 | ( - | _____^ -23 | | [1, 2], -24 | | [3, 4], -25 | | ), - | |_____^ PT007 -26 | ) -27 | def test_tuple_of_lists(param1, param2): - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -19 19 | -20 20 | @pytest.mark.parametrize( -21 21 | ("param1", "param2"), -22 |- ( - 22 |+ [ -23 23 | [1, 2], -24 24 | [3, 4], -25 |- ), - 25 |+ ], -26 26 | ) -27 27 | def test_tuple_of_lists(param1, param2): -28 28 | ... - -PT007.py:39:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -37 | ("param1", "param2"), -38 | [ -39 | (1, 2), - | ^^^^^^ PT007 -40 | (3, 4), -41 | ], - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -36 36 | @pytest.mark.parametrize( -37 37 | ("param1", "param2"), -38 38 | [ -39 |- (1, 2), - 39 |+ [1, 2], -40 40 | (3, 4), -41 41 | ], -42 42 | ) - -PT007.py:40:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -38 | [ -39 | (1, 2), -40 | (3, 4), - | ^^^^^^ PT007 -41 | ], -42 | ) - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -37 37 | ("param1", "param2"), -38 38 | [ -39 39 | (1, 2), -40 |- (3, 4), - 40 |+ [3, 4], -41 41 | ], -42 42 | ) -43 43 | def test_list_of_tuples(param1, param2): - -PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^^^^^^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @pytest.mark.parametrize( -84 84 | "d", - -PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @pytest.mark.parametrize( -84 84 | "d", - -PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `list` of `list` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @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 3f208a2d6ce52..2ee341b846203 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_list_of_tuples.snap.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new deleted file mode 100644 index 2d6e991d202da..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap.new +++ /dev/null @@ -1,226 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs -assertion_line: 303 ---- -PT007.py:4:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -4 | @pytest.mark.parametrize("param", (1, 2)) - | ^^^^^^ PT007 -5 | def test_tuple(param): -6 | ... - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -1 1 | import pytest -2 2 | -3 3 | -4 |-@pytest.mark.parametrize("param", (1, 2)) - 4 |+@pytest.mark.parametrize("param", [1, 2]) -5 5 | def test_tuple(param): -6 6 | ... -7 7 | - -PT007.py:11:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | - 9 | @pytest.mark.parametrize( -10 | ("param1", "param2"), -11 | ( - | _____^ -12 | | (1, 2), -13 | | (3, 4), -14 | | ), - | |_____^ PT007 -15 | ) -16 | def test_tuple_of_tuples(param1, param2): - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -8 8 | -9 9 | @pytest.mark.parametrize( -10 10 | ("param1", "param2"), -11 |- ( - 11 |+ [ -12 12 | (1, 2), -13 13 | (3, 4), -14 |- ), - 14 |+ ], -15 15 | ) -16 16 | def test_tuple_of_tuples(param1, param2): -17 17 | ... - -PT007.py:22:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -20 | @pytest.mark.parametrize( -21 | ("param1", "param2"), -22 | ( - | _____^ -23 | | [1, 2], -24 | | [3, 4], -25 | | ), - | |_____^ PT007 -26 | ) -27 | def test_tuple_of_lists(param1, param2): - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -19 19 | -20 20 | @pytest.mark.parametrize( -21 21 | ("param1", "param2"), -22 |- ( - 22 |+ [ -23 23 | [1, 2], -24 24 | [3, 4], -25 |- ), - 25 |+ ], -26 26 | ) -27 27 | def test_tuple_of_lists(param1, param2): -28 28 | ... - -PT007.py:23:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -21 | ("param1", "param2"), -22 | ( -23 | [1, 2], - | ^^^^^^ PT007 -24 | [3, 4], -25 | ), - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -20 20 | @pytest.mark.parametrize( -21 21 | ("param1", "param2"), -22 22 | ( -23 |- [1, 2], - 23 |+ (1, 2), -24 24 | [3, 4], -25 25 | ), -26 26 | ) - -PT007.py:24:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -22 | ( -23 | [1, 2], -24 | [3, 4], - | ^^^^^^ PT007 -25 | ), -26 | ) - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -21 21 | ("param1", "param2"), -22 22 | ( -23 23 | [1, 2], -24 |- [3, 4], - 24 |+ (3, 4), -25 25 | ), -26 26 | ) -27 27 | def test_tuple_of_lists(param1, param2): - -PT007.py:50:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -48 | ("param1", "param2"), -49 | [ -50 | [1, 2], - | ^^^^^^ PT007 -51 | [3, 4], -52 | ], - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -47 47 | @pytest.mark.parametrize( -48 48 | ("param1", "param2"), -49 49 | [ -50 |- [1, 2], - 50 |+ (1, 2), -51 51 | [3, 4], -52 52 | ], -53 53 | ) - -PT007.py:51:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -49 | [ -50 | [1, 2], -51 | [3, 4], - | ^^^^^^ PT007 -52 | ], -53 | ) - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -48 48 | ("param1", "param2"), -49 49 | [ -50 50 | [1, 2], -51 |- [3, 4], - 51 |+ (3, 4), -52 52 | ], -53 53 | ) -54 54 | def test_list_of_lists(param1, param2): - -PT007.py:61:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -59 | "param1,param2", -60 | [ -61 | [1, 2], - | ^^^^^^ PT007 -62 | [3, 4], -63 | ], - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -58 58 | @pytest.mark.parametrize( -59 59 | "param1,param2", -60 60 | [ -61 |- [1, 2], - 61 |+ (1, 2), -62 62 | [3, 4], -63 63 | ], -64 64 | ) - -PT007.py:62:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -60 | [ -61 | [1, 2], -62 | [3, 4], - | ^^^^^^ PT007 -63 | ], -64 | ) - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -59 59 | "param1,param2", -60 60 | [ -61 61 | [1, 2], -62 |- [3, 4], - 62 |+ (3, 4), -63 63 | ], -64 64 | ) -65 65 | def test_csv_name_list_of_lists(param1, param2): - -PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^^^^^^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `list` of `tuple` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @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 55aea05664b54..93a0b2954c463 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_lists.snap.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new deleted file mode 100644 index 49c526e181b5e..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap.new +++ /dev/null @@ -1,323 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs -assertion_line: 303 ---- -PT007.py:12:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -10 | ("param1", "param2"), -11 | ( -12 | (1, 2), - | ^^^^^^ PT007 -13 | (3, 4), -14 | ), - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -9 9 | @pytest.mark.parametrize( -10 10 | ("param1", "param2"), -11 11 | ( -12 |- (1, 2), - 12 |+ [1, 2], -13 13 | (3, 4), -14 14 | ), -15 15 | ) - -PT007.py:13:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -11 | ( -12 | (1, 2), -13 | (3, 4), - | ^^^^^^ PT007 -14 | ), -15 | ) - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -10 10 | ("param1", "param2"), -11 11 | ( -12 12 | (1, 2), -13 |- (3, 4), - 13 |+ [3, 4], -14 14 | ), -15 15 | ) -16 16 | def test_tuple_of_tuples(param1, param2): - -PT007.py:31:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -31 | @pytest.mark.parametrize("param", [1, 2]) - | ^^^^^^ PT007 -32 | def test_list(param): -33 | ... - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -28 28 | ... -29 29 | -30 30 | -31 |-@pytest.mark.parametrize("param", [1, 2]) - 31 |+@pytest.mark.parametrize("param", (1, 2)) -32 32 | def test_list(param): -33 33 | ... -34 34 | - -PT007.py:38:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -36 | @pytest.mark.parametrize( -37 | ("param1", "param2"), -38 | [ - | _____^ -39 | | (1, 2), -40 | | (3, 4), -41 | | ], - | |_____^ PT007 -42 | ) -43 | def test_list_of_tuples(param1, param2): - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -35 35 | -36 36 | @pytest.mark.parametrize( -37 37 | ("param1", "param2"), -38 |- [ - 38 |+ ( -39 39 | (1, 2), -40 40 | (3, 4), -41 |- ], - 41 |+ ), -42 42 | ) -43 43 | def test_list_of_tuples(param1, param2): -44 44 | ... - -PT007.py:39:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -37 | ("param1", "param2"), -38 | [ -39 | (1, 2), - | ^^^^^^ PT007 -40 | (3, 4), -41 | ], - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -36 36 | @pytest.mark.parametrize( -37 37 | ("param1", "param2"), -38 38 | [ -39 |- (1, 2), - 39 |+ [1, 2], -40 40 | (3, 4), -41 41 | ], -42 42 | ) - -PT007.py:40:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -38 | [ -39 | (1, 2), -40 | (3, 4), - | ^^^^^^ PT007 -41 | ], -42 | ) - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -37 37 | ("param1", "param2"), -38 38 | [ -39 39 | (1, 2), -40 |- (3, 4), - 40 |+ [3, 4], -41 41 | ], -42 42 | ) -43 43 | def test_list_of_tuples(param1, param2): - -PT007.py:49:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -47 | @pytest.mark.parametrize( -48 | ("param1", "param2"), -49 | [ - | _____^ -50 | | [1, 2], -51 | | [3, 4], -52 | | ], - | |_____^ PT007 -53 | ) -54 | def test_list_of_lists(param1, param2): - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -46 46 | -47 47 | @pytest.mark.parametrize( -48 48 | ("param1", "param2"), -49 |- [ - 49 |+ ( -50 50 | [1, 2], -51 51 | [3, 4], -52 |- ], - 52 |+ ), -53 53 | ) -54 54 | def test_list_of_lists(param1, param2): -55 55 | ... - -PT007.py:60:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -58 | @pytest.mark.parametrize( -59 | "param1,param2", -60 | [ - | _____^ -61 | | [1, 2], -62 | | [3, 4], -63 | | ], - | |_____^ PT007 -64 | ) -65 | def test_csv_name_list_of_lists(param1, param2): - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -57 57 | -58 58 | @pytest.mark.parametrize( -59 59 | "param1,param2", -60 |- [ - 60 |+ ( -61 61 | [1, 2], -62 62 | [3, 4], -63 |- ], - 63 |+ ), -64 64 | ) -65 65 | def test_csv_name_list_of_lists(param1, param2): -66 66 | ... - -PT007.py:71:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -69 | @pytest.mark.parametrize( -70 | "param", -71 | [ - | _____^ -72 | | [1, 2], -73 | | [3, 4], -74 | | ], - | |_____^ PT007 -75 | ) -76 | def test_single_list_of_lists(param): - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -68 68 | -69 69 | @pytest.mark.parametrize( -70 70 | "param", -71 |- [ - 71 |+ ( -72 72 | [1, 2], -73 73 | [3, 4], -74 |- ], - 74 |+ ), -75 75 | ) -76 76 | def test_single_list_of_lists(param): -77 77 | ... - -PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) - | ^^^^^^ PT007 -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) -82 | @pytest.mark.parametrize("d", [3,]) - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -77 77 | ... -78 78 | -79 79 | -80 |-@pytest.mark.parametrize("a", [1, 2]) - 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 | @pytest.mark.parametrize( - -PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @pytest.mark.parametrize( -84 84 | "d", - -PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) - | ^^^^^^ PT007 -82 | @pytest.mark.parametrize("d", [3,]) -83 | @pytest.mark.parametrize( - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -78 78 | -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @pytest.mark.parametrize( -84 84 | "d", - -PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) -82 | @pytest.mark.parametrize("d", [3,]) - | ^^^^ PT007 -83 | @pytest.mark.parametrize( -84 | "d", - | - = help: Use `tuple` of `list` for parameter values - -ℹ Unsafe fix -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @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 | def test_multiple_decorators(a, b, c): - | - = 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 | def test_multiple_decorators(a, b, c): -88 88 | 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 d38c58b152a24..3d90a13b2eb9c 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 diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new deleted file mode 100644 index c9fff8ccbc99b..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap.new +++ /dev/null @@ -1,325 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs -assertion_line: 303 ---- -PT007.py:23:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -21 | ("param1", "param2"), -22 | ( -23 | [1, 2], - | ^^^^^^ PT007 -24 | [3, 4], -25 | ), - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -20 20 | @pytest.mark.parametrize( -21 21 | ("param1", "param2"), -22 22 | ( -23 |- [1, 2], - 23 |+ (1, 2), -24 24 | [3, 4], -25 25 | ), -26 26 | ) - -PT007.py:24:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -22 | ( -23 | [1, 2], -24 | [3, 4], - | ^^^^^^ PT007 -25 | ), -26 | ) - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -21 21 | ("param1", "param2"), -22 22 | ( -23 23 | [1, 2], -24 |- [3, 4], - 24 |+ (3, 4), -25 25 | ), -26 26 | ) -27 27 | def test_tuple_of_lists(param1, param2): - -PT007.py:31:35: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -31 | @pytest.mark.parametrize("param", [1, 2]) - | ^^^^^^ PT007 -32 | def test_list(param): -33 | ... - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -28 28 | ... -29 29 | -30 30 | -31 |-@pytest.mark.parametrize("param", [1, 2]) - 31 |+@pytest.mark.parametrize("param", (1, 2)) -32 32 | def test_list(param): -33 33 | ... -34 34 | - -PT007.py:38:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -36 | @pytest.mark.parametrize( -37 | ("param1", "param2"), -38 | [ - | _____^ -39 | | (1, 2), -40 | | (3, 4), -41 | | ], - | |_____^ PT007 -42 | ) -43 | def test_list_of_tuples(param1, param2): - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -35 35 | -36 36 | @pytest.mark.parametrize( -37 37 | ("param1", "param2"), -38 |- [ - 38 |+ ( -39 39 | (1, 2), -40 40 | (3, 4), -41 |- ], - 41 |+ ), -42 42 | ) -43 43 | def test_list_of_tuples(param1, param2): -44 44 | ... - -PT007.py:49:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -47 | @pytest.mark.parametrize( -48 | ("param1", "param2"), -49 | [ - | _____^ -50 | | [1, 2], -51 | | [3, 4], -52 | | ], - | |_____^ PT007 -53 | ) -54 | def test_list_of_lists(param1, param2): - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -46 46 | -47 47 | @pytest.mark.parametrize( -48 48 | ("param1", "param2"), -49 |- [ - 49 |+ ( -50 50 | [1, 2], -51 51 | [3, 4], -52 |- ], - 52 |+ ), -53 53 | ) -54 54 | def test_list_of_lists(param1, param2): -55 55 | ... - -PT007.py:50:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -48 | ("param1", "param2"), -49 | [ -50 | [1, 2], - | ^^^^^^ PT007 -51 | [3, 4], -52 | ], - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -47 47 | @pytest.mark.parametrize( -48 48 | ("param1", "param2"), -49 49 | [ -50 |- [1, 2], - 50 |+ (1, 2), -51 51 | [3, 4], -52 52 | ], -53 53 | ) - -PT007.py:51:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -49 | [ -50 | [1, 2], -51 | [3, 4], - | ^^^^^^ PT007 -52 | ], -53 | ) - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -48 48 | ("param1", "param2"), -49 49 | [ -50 50 | [1, 2], -51 |- [3, 4], - 51 |+ (3, 4), -52 52 | ], -53 53 | ) -54 54 | def test_list_of_lists(param1, param2): - -PT007.py:60:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -58 | @pytest.mark.parametrize( -59 | "param1,param2", -60 | [ - | _____^ -61 | | [1, 2], -62 | | [3, 4], -63 | | ], - | |_____^ PT007 -64 | ) -65 | def test_csv_name_list_of_lists(param1, param2): - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -57 57 | -58 58 | @pytest.mark.parametrize( -59 59 | "param1,param2", -60 |- [ - 60 |+ ( -61 61 | [1, 2], -62 62 | [3, 4], -63 |- ], - 63 |+ ), -64 64 | ) -65 65 | def test_csv_name_list_of_lists(param1, param2): -66 66 | ... - -PT007.py:61:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -59 | "param1,param2", -60 | [ -61 | [1, 2], - | ^^^^^^ PT007 -62 | [3, 4], -63 | ], - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -58 58 | @pytest.mark.parametrize( -59 59 | "param1,param2", -60 60 | [ -61 |- [1, 2], - 61 |+ (1, 2), -62 62 | [3, 4], -63 63 | ], -64 64 | ) - -PT007.py:62:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -60 | [ -61 | [1, 2], -62 | [3, 4], - | ^^^^^^ PT007 -63 | ], -64 | ) - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -59 59 | "param1,param2", -60 60 | [ -61 61 | [1, 2], -62 |- [3, 4], - 62 |+ (3, 4), -63 63 | ], -64 64 | ) -65 65 | def test_csv_name_list_of_lists(param1, param2): - -PT007.py:71:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -69 | @pytest.mark.parametrize( -70 | "param", -71 | [ - | _____^ -72 | | [1, 2], -73 | | [3, 4], -74 | | ], - | |_____^ PT007 -75 | ) -76 | def test_single_list_of_lists(param): - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -68 68 | -69 69 | @pytest.mark.parametrize( -70 70 | "param", -71 |- [ - 71 |+ ( -72 72 | [1, 2], -73 73 | [3, 4], -74 |- ], - 74 |+ ), -75 75 | ) -76 76 | def test_single_list_of_lists(param): -77 77 | ... - -PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -80 | @pytest.mark.parametrize("a", [1, 2]) - | ^^^^^^ PT007 -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) -82 | @pytest.mark.parametrize("d", [3,]) - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -77 77 | ... -78 78 | -79 79 | -80 |-@pytest.mark.parametrize("a", [1, 2]) - 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 | @pytest.mark.parametrize( - -PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` - | -80 | @pytest.mark.parametrize("a", [1, 2]) -81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) -82 | @pytest.mark.parametrize("d", [3,]) - | ^^^^ PT007 -83 | @pytest.mark.parametrize( -84 | "d", - | - = help: Use `tuple` of `tuple` for parameter values - -ℹ Unsafe fix -79 79 | -80 80 | @pytest.mark.parametrize("a", [1, 2]) -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 | @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 | def test_multiple_decorators(a, b, c): - | - = 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 | def test_multiple_decorators(a, b, c): -88 88 | pass diff --git a/foo/bar.py b/foo/bar.py deleted file mode 100644 index 556ad16d4c3b6..0000000000000 --- a/foo/bar.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest -from pytest_mock import MockFixture - -from module.sub import ( - get_value, -) - - -@pytest.fixture -def mock_check_output(mocker: MockFixture, output: bytes): - return mocker.patch("subprocess.check_output", return_value=output) - - -@pytest.mark.parametrize( - "output, expected_result", - [(b"apple", "apple")], -) -def test_get_value(mock_check_output, expected_result): - assert get_value() == expected_result - mock_check_output.assert_called_once() diff --git a/foo/ruff.toml b/foo/ruff.toml deleted file mode 100644 index b15068d3f8f37..0000000000000 --- a/foo/ruff.toml +++ /dev/null @@ -1,26 +0,0 @@ -line-length = 120 - -target-version = "py38" - -lint.extend-select = [ - "W", # whitespace - "I", # imports - - # pytest - "PT001", # pytest-fixture-incorrect-parentheses-style - "PT006", # pytest-parametrize-names-wrong-type - "PT007", # pytest-parametrize-values-wrong-type - "PT025", # pytest-erroneous-use-fixtures-on-fixture - "PT026", # pytest-use-fixtures-without-parameters -] - -[ lint.isort ] - -known-first-party = ["module"] - -[ lint.flake8-pytest-style ] - -fixture-parentheses = false -parametrize-names-type = "csv" -parametrize-values-row-type = "tuple" -parametrize-values-type = "tuple"