[`flake8-pytest-style`] Add automatic fix for `pytest-parametrize-values-wrong-type` (`PT007`) (#10461)

## Summary

This adds automatic fixes for the `PT007` rule.

I am currently reviewing and adding Ruff rules to Home Assistant. One
rule is PT007, which has multiple hundred occurrences in the codebase,
but no automatic fix, and this is not fun to do manually, especially
because using Regexes are not really possible with this.

My knowledge of the Ruff codebase and Rust in general is not good and
this is my first PR here, so I hope it is not too bad.

One thing where I need help is: How can I have the transformed code to
be formatted automatically, instead of it being minimized as it does it
now?

## Test Plan

Using the existing fixtures and updated snapshots.
This commit is contained in:
Sid 2024-03-18 21:28:49 +01:00 committed by GitHub
parent ae0ff9b029
commit 1a2f9f082d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 774 additions and 70 deletions

View File

@ -79,5 +79,6 @@ 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):
pass

View File

@ -182,11 +182,18 @@ pub struct PytestParametrizeValuesWrongType {
}
impl Violation for PytestParametrizeValuesWrongType {
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
let PytestParametrizeValuesWrongType { values, row } = self;
format!("Wrong values type in `@pytest.mark.parametrize` expected `{values}` of `{row}`")
}
fn fix_title(&self) -> Option<String> {
let PytestParametrizeValuesWrongType { values, row } = self;
Some(format!("Use `{values}` of `{row}` for parameter values"))
}
}
/// ## What it does
@ -493,13 +500,46 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
match values {
Expr::List(ast::ExprList { elts, .. }) => {
if values_type != types::ParametrizeValuesType::List {
checker.diagnostics.push(Diagnostic::new(
let mut diagnostic = Diagnostic::new(
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
values.range(),
));
);
diagnostic.set_fix({
// Determine whether the last element has a trailing comma. Single-element
// tuples _require_ a trailing comma, so this is a single-element list
// _without_ a trailing comma, we need to insert one.
let needs_trailing_comma = if let [item] = elts.as_slice() {
SimpleTokenizer::new(
checker.locator().contents(),
TextRange::new(item.end(), values.end()),
)
.all(|token| token.kind != SimpleTokenKind::Comma)
} else {
false
};
// Replace `[` with `(`.
let values_start = Edit::replacement(
"(".into(),
values.start(),
values.start() + TextSize::from(1),
);
// Replace `]` with `)` or `,)`.
let values_end = Edit::replacement(
if needs_trailing_comma {
"),".into()
} else {
")".into()
},
values.end() - TextSize::from(1),
values.end(),
);
Fix::unsafe_edits(values_start, [values_end])
});
checker.diagnostics.push(diagnostic);
}
if is_multi_named {
@ -508,14 +548,48 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
}
Expr::Tuple(ast::ExprTuple { elts, .. }) => {
if values_type != types::ParametrizeValuesType::Tuple {
checker.diagnostics.push(Diagnostic::new(
let mut diagnostic = Diagnostic::new(
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
values.range(),
));
);
diagnostic.set_fix({
// Determine whether a trailing comma is present due to the _requirement_
// that a single-element tuple must have a trailing comma, e.g., `(1,)`.
//
// If the trailing comma is on its own line, we intentionally ignore it,
// since the expression is already split over multiple lines, as in:
// ```python
// @pytest.mark.parametrize(
// (
// "x",
// ),
// )
// ```
let has_trailing_comma = elts.len() == 1
&& checker.locator().up_to(values.end()).chars().rev().nth(1) == Some(',');
// Replace `(` with `[`.
let values_start = Edit::replacement(
"[".into(),
values.start(),
values.start() + TextSize::from(1),
);
// Replace `)` or `,)` with `]`.
let start = if has_trailing_comma {
values.end() - TextSize::from(2)
} else {
values.end() - TextSize::from(1)
};
let values_end = Edit::replacement("]".into(), start, values.end());
Fix::unsafe_edits(values_start, [values_end])
});
checker.diagnostics.push(diagnostic);
}
if is_multi_named {
handle_value_rows(checker, elts, values_type, values_row_type);
}
@ -604,26 +678,91 @@ fn handle_value_rows(
) {
for elt in elts {
match elt {
Expr::Tuple(_) => {
Expr::Tuple(ast::ExprTuple { elts, .. }) => {
if values_row_type != types::ParametrizeValuesRowType::Tuple {
checker.diagnostics.push(Diagnostic::new(
let mut diagnostic = Diagnostic::new(
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
elt.range(),
));
);
diagnostic.set_fix({
// Determine whether a trailing comma is present due to the _requirement_
// that a single-element tuple must have a trailing comma, e.g., `(1,)`.
//
// If the trailing comma is on its own line, we intentionally ignore it,
// since the expression is already split over multiple lines, as in:
// ```python
// @pytest.mark.parametrize(
// (
// "x",
// ),
// )
// ```
let has_trailing_comma = elts.len() == 1
&& checker.locator().up_to(elt.end()).chars().rev().nth(1) == Some(',');
// Replace `(` with `[`.
let elt_start = Edit::replacement(
"[".into(),
elt.start(),
elt.start() + TextSize::from(1),
);
// Replace `)` or `,)` with `]`.
let start = if has_trailing_comma {
elt.end() - TextSize::from(2)
} else {
elt.end() - TextSize::from(1)
};
let elt_end = Edit::replacement("]".into(), start, elt.end());
Fix::unsafe_edits(elt_start, [elt_end])
});
checker.diagnostics.push(diagnostic);
}
}
Expr::List(_) => {
Expr::List(ast::ExprList { elts, .. }) => {
if values_row_type != types::ParametrizeValuesRowType::List {
checker.diagnostics.push(Diagnostic::new(
let mut diagnostic = Diagnostic::new(
PytestParametrizeValuesWrongType {
values: values_type,
row: values_row_type,
},
elt.range(),
));
);
diagnostic.set_fix({
// Determine whether the last element has a trailing comma. Single-element
// tuples _require_ a trailing comma, so this is a single-element list
// _without_ a trailing comma, we need to insert one.
let needs_trailing_comma = if let [item] = elts.as_slice() {
SimpleTokenizer::new(
checker.locator().contents(),
TextRange::new(item.end(), elt.end()),
)
.all(|token| token.kind != SimpleTokenKind::Comma)
} else {
false
};
// Replace `[` with `(`.
let elt_start = Edit::replacement(
"(".into(),
elt.start(),
elt.start() + TextSize::from(1),
);
// Replace `]` with `)` or `,)`.
let elt_end = Edit::replacement(
if needs_trailing_comma {
",)".into()
} else {
")".into()
},
elt.end() - TextSize::from(1),
elt.end(),
);
Fix::unsafe_edits(elt_start, [elt_end])
});
checker.diagnostics.push(diagnostic);
}
}
_ => {}

View File

@ -1,15 +1,26 @@
---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT007.py:4:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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
PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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"),
@ -22,8 +33,23 @@ PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
15 | )
16 | def test_tuple_of_tuples(param1, param2):
|
= help: Use `list` of `list` for parameter values
PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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 | (
@ -32,8 +58,19 @@ PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
13 | (3, 4),
14 | ),
|
= help: Use `list` of `list` for parameter values
PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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),
@ -42,8 +79,19 @@ PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
14 | ),
15 | )
|
= help: Use `list` of `list` for parameter values
PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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"),
@ -56,8 +104,23 @@ PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
26 | )
27 | def test_tuple_of_lists(param1, param2):
|
= help: Use `list` of `list` for parameter values
PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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 | [
@ -66,8 +129,19 @@ PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
40 | (3, 4),
41 | ],
|
= help: Use `list` of `list` for parameter values
PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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),
@ -76,32 +150,74 @@ PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
41 | ],
42 | )
|
= help: Use `list` of `list` for parameter values
PT007.py:81:38: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= help: Use `list` of `list` for parameter values
PT007.py:81:39: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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 | def test_multiple_decorators(a, b, c):
84 84 | pass
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= help: Use `list` of `list` for parameter values
PT007.py:81:47: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
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 | def test_multiple_decorators(a, b, c):
84 84 | pass
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= 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 | def test_multiple_decorators(a, b, c):
84 84 | pass

View File

@ -1,15 +1,26 @@
---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT007.py:4:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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
PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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"),
@ -22,8 +33,23 @@ PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
15 | )
16 | def test_tuple_of_tuples(param1, param2):
|
= help: Use `list` of `tuple` for parameter values
PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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"),
@ -36,8 +62,23 @@ PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
26 | )
27 | def test_tuple_of_lists(param1, param2):
|
= help: Use `list` of `tuple` for parameter values
PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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 | (
@ -46,8 +87,19 @@ PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
24 | [3, 4],
25 | ),
|
= help: Use `list` of `tuple` for parameter values
PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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],
@ -56,8 +108,19 @@ PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
25 | ),
26 | )
|
= help: Use `list` of `tuple` for parameter values
PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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 | [
@ -66,8 +129,19 @@ PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
51 | [3, 4],
52 | ],
|
= help: Use `list` of `tuple` for parameter values
PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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],
@ -76,8 +150,19 @@ PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
52 | ],
53 | )
|
= help: Use `list` of `tuple` for parameter values
PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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 | [
@ -86,8 +171,19 @@ PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
62 | [3, 4],
63 | ],
|
= help: Use `list` of `tuple` for parameter values
PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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],
@ -96,14 +192,34 @@ PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `l
63 | ],
64 | )
|
= help: Use `list` of `tuple` for parameter values
PT007.py:81:38: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= 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 | def test_multiple_decorators(a, b, c):
84 84 | pass

View File

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
PT007.py:12:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
|
10 | ("param1", "param2"),
11 | (
@ -10,8 +10,19 @@ PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
13 | (3, 4),
14 | ),
|
= help: Use `tuple` of `list` for parameter values
PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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),
@ -20,16 +31,38 @@ PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
14 | ),
15 | )
|
= help: Use `tuple` of `list` for parameter values
PT007.py:31:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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
PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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"),
@ -42,8 +75,23 @@ PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
42 | )
43 | def test_list_of_tuples(param1, param2):
|
= help: Use `tuple` of `list` for parameter values
PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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 | [
@ -52,8 +100,19 @@ PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
40 | (3, 4),
41 | ],
|
= help: Use `tuple` of `list` for parameter values
PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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),
@ -62,8 +121,19 @@ PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
41 | ],
42 | )
|
= help: Use `tuple` of `list` for parameter values
PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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"),
@ -76,8 +146,23 @@ PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
53 | )
54 | def test_list_of_lists(param1, param2):
|
= help: Use `tuple` of `list` for parameter values
PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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",
@ -90,8 +175,23 @@ PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
64 | )
65 | def test_csv_name_list_of_lists(param1, param2):
|
= help: Use `tuple` of `list` for parameter values
PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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",
@ -104,31 +204,97 @@ PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
75 | )
76 | def test_single_list_of_lists(param):
|
= help: Use `tuple` of `list` for parameter values
PT007.py:80:31: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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 | def test_multiple_decorators(a, b, c):
82 | @pytest.mark.parametrize("d", [3,])
|
= help: Use `tuple` of `list` for parameter values
PT007.py:81:39: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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 | def test_multiple_decorators(a, b, c):
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= help: Use `tuple` of `list` for parameter values
PT007.py:81:47: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
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 | def test_multiple_decorators(a, b, c):
84 84 | pass
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 | def test_multiple_decorators(a, b, c):
83 | pass
82 | @pytest.mark.parametrize("d", [3,])
83 | def test_multiple_decorators(a, b, c):
|
= 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 | def test_multiple_decorators(a, b, c):
84 84 | pass
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 | def test_multiple_decorators(a, b, c):
84 | pass
|
= 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 | def test_multiple_decorators(a, b, c):
84 84 | pass

View File

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
PT007.py:23:9: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
|
21 | ("param1", "param2"),
22 | (
@ -10,8 +10,19 @@ PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
24 | [3, 4],
25 | ),
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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],
@ -20,16 +31,38 @@ PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
25 | ),
26 | )
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:31:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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
PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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"),
@ -42,8 +75,23 @@ PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
42 | )
43 | def test_list_of_tuples(param1, param2):
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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"),
@ -56,8 +104,23 @@ PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
53 | )
54 | def test_list_of_lists(param1, param2):
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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 | [
@ -66,8 +129,19 @@ PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
51 | [3, 4],
52 | ],
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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],
@ -76,8 +150,19 @@ PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
52 | ],
53 | )
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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",
@ -90,8 +175,23 @@ PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
64 | )
65 | def test_csv_name_list_of_lists(param1, param2):
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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 | [
@ -100,8 +200,19 @@ PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
62 | [3, 4],
63 | ],
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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],
@ -110,8 +221,19 @@ PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
63 | ],
64 | )
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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",
@ -124,13 +246,57 @@ PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `t
75 | )
76 | def test_single_list_of_lists(param):
|
= help: Use `tuple` of `tuple` for parameter values
PT007.py:80:31: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
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 | def test_multiple_decorators(a, b, c):
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 | def test_multiple_decorators(a, b, c):
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 | def test_multiple_decorators(a, b, c):
84 | pass
|
= 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 | def test_multiple_decorators(a, b, c):
84 84 | pass