mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Accommodate multiple @pytest.mark.parametrize
decorators (#2662)
This commit is contained in:
parent
9cd1bf9c03
commit
9f9f25ff7c
6 changed files with 126 additions and 29 deletions
|
@ -75,3 +75,9 @@ def test_csv_name_list_of_lists(param1, param2):
|
|||
)
|
||||
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> {
|
||||
let all_literals = elts.iter().all(|e| {
|
||||
matches!(
|
||||
|
@ -377,26 +371,27 @@ fn handle_value_rows(
|
|||
}
|
||||
|
||||
pub fn parametrize(checker: &mut Checker, decorators: &[Expr]) {
|
||||
let decorator = get_parametrize_decorator(checker, decorators);
|
||||
if let Some(decorator) = decorator {
|
||||
if let ExprKind::Call { args, .. } = &decorator.node {
|
||||
if checker
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ParametrizeNamesWrongType)
|
||||
{
|
||||
if let Some(names) = args.get(0) {
|
||||
check_names(checker, names);
|
||||
for decorator in decorators {
|
||||
if is_pytest_parametrize(decorator, checker) {
|
||||
if let ExprKind::Call { args, .. } = &decorator.node {
|
||||
if checker
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ParametrizeNamesWrongType)
|
||||
{
|
||||
if let Some(names) = args.get(0) {
|
||||
check_names(checker, names);
|
||||
}
|
||||
}
|
||||
}
|
||||
if checker
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ParametrizeValuesWrongType)
|
||||
{
|
||||
if let Some(names) = args.get(0) {
|
||||
if let Some(values) = args.get(1) {
|
||||
check_values(checker, names, values);
|
||||
if checker
|
||||
.settings
|
||||
.rules
|
||||
.enabled(&Rule::ParametrizeValuesWrongType)
|
||||
{
|
||||
if let Some(names) = args.get(0) {
|
||||
if let Some(values) = args.get(1) {
|
||||
check_values(checker, names, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
source: src/rules/flake8_pytest_style/mod.rs
|
||||
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
|
@ -86,4 +86,40 @@ expression: diagnostics
|
|||
column: 14
|
||||
fix: ~
|
||||
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
|
||||
---
|
||||
- kind:
|
||||
|
@ -110,4 +110,16 @@ expression: diagnostics
|
|||
column: 14
|
||||
fix: ~
|
||||
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
|
||||
---
|
||||
- kind:
|
||||
|
@ -110,4 +110,40 @@ expression: diagnostics
|
|||
column: 5
|
||||
fix: ~
|
||||
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
|
||||
---
|
||||
- kind:
|
||||
|
@ -134,4 +134,16 @@ expression: diagnostics
|
|||
column: 5
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeValuesWrongType:
|
||||
values: tuple
|
||||
row: tuple
|
||||
location:
|
||||
row: 80
|
||||
column: 30
|
||||
end_location:
|
||||
row: 80
|
||||
column: 36
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue