mirror of https://github.com/astral-sh/ruff
Accommodate multiple `@pytest.mark.parametrize` decorators (#2662)
This commit is contained in:
parent
9cd1bf9c03
commit
9f9f25ff7c
|
|
@ -75,3 +75,9 @@ def test_csv_name_list_of_lists(param1, param2):
|
||||||
)
|
)
|
||||||
def test_single_list_of_lists(param):
|
def test_single_list_of_lists(param):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("a", [1, 2])
|
||||||
|
@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
|
||||||
|
def test_multiple_decorators(a, b, c):
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,6 @@ impl Violation for ParametrizeValuesWrongType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_parametrize_decorator<'a>(checker: &Checker, decorators: &'a [Expr]) -> Option<&'a Expr> {
|
|
||||||
decorators
|
|
||||||
.iter()
|
|
||||||
.find(|decorator| is_pytest_parametrize(decorator, checker))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn elts_to_csv(elts: &[Expr], checker: &Checker) -> Option<String> {
|
fn elts_to_csv(elts: &[Expr], checker: &Checker) -> Option<String> {
|
||||||
let all_literals = elts.iter().all(|e| {
|
let all_literals = elts.iter().all(|e| {
|
||||||
matches!(
|
matches!(
|
||||||
|
|
@ -377,8 +371,8 @@ fn handle_value_rows(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
|
pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
|
||||||
let decorator = get_parametrize_decorator(checker, decorators);
|
for decorator in decorators {
|
||||||
if let Some(decorator) = decorator {
|
if is_pytest_parametrize(decorator, checker) {
|
||||||
if let ExprKind::Call { args, .. } = &decorator.node {
|
if let ExprKind::Call { args, .. } = &decorator.node {
|
||||||
if checker
|
if checker
|
||||||
.settings
|
.settings
|
||||||
|
|
@ -402,4 +396,5 @@ pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_pytest_style/mod.rs
|
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
|
|
@ -86,4 +86,40 @@ expression: diagnostics
|
||||||
column: 14
|
column: 14
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: list
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 37
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 53
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: list
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 38
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 44
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: list
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 46
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 52
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_pytest_style/mod.rs
|
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
|
|
@ -110,4 +110,16 @@ expression: diagnostics
|
||||||
column: 14
|
column: 14
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: list
|
||||||
|
row: tuple
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 37
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 53
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_pytest_style/mod.rs
|
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
|
|
@ -110,4 +110,40 @@ expression: diagnostics
|
||||||
column: 5
|
column: 5
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: tuple
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 80
|
||||||
|
column: 30
|
||||||
|
end_location:
|
||||||
|
row: 80
|
||||||
|
column: 36
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: tuple
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 38
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 44
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: tuple
|
||||||
|
row: list
|
||||||
|
location:
|
||||||
|
row: 81
|
||||||
|
column: 46
|
||||||
|
end_location:
|
||||||
|
row: 81
|
||||||
|
column: 52
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_pytest_style/mod.rs
|
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
|
|
@ -134,4 +134,16 @@ expression: diagnostics
|
||||||
column: 5
|
column: 5
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
ParametrizeValuesWrongType:
|
||||||
|
values: tuple
|
||||||
|
row: tuple
|
||||||
|
location:
|
||||||
|
row: 80
|
||||||
|
column: 30
|
||||||
|
end_location:
|
||||||
|
row: 80
|
||||||
|
column: 36
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue