Skip to content

Commit 1eee6f1

Browse files
[flake8-pytest-style] Fix single-tuple conversion in pytest-parametrize-values-wrong-type (#10862)
## Summary This looks like a typo (without test coverage). Closes #10861.
1 parent de46a36 commit 1eee6f1

6 files changed

+124
-30
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT007.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,13 @@ def test_single_list_of_lists(param):
8080
@pytest.mark.parametrize("a", [1, 2])
8181
@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
8282
@pytest.mark.parametrize("d", [3,])
83-
def test_multiple_decorators(a, b, c):
83+
@pytest.mark.parametrize(
84+
"d",
85+
[("3", "4")],
86+
)
87+
@pytest.mark.parametrize(
88+
"e",
89+
[("3", "4"),],
90+
)
91+
def test_multiple_decorators(a, b, c, d, e):
8492
pass

crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ fn check_values(checker: &mut Checker, names: &Expr, values: &Expr) {
567567
// Replace `]` with `)` or `,)`.
568568
let values_end = Edit::replacement(
569569
if needs_trailing_comma {
570-
"),".into()
570+
",)".into()
571571
} else {
572572
")".into()
573573
},

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
168168
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
169169
| ^^^^^^^^^^^^^^^^ PT007
170170
82 | @pytest.mark.parametrize("d", [3,])
171-
83 | def test_multiple_decorators(a, b, c):
171+
83 | @pytest.mark.parametrize(
172172
|
173173
= help: Use `list` of `list` for parameter values
174174

@@ -179,16 +179,16 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
179179
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
180180
81 |+@pytest.mark.parametrize(("b", "c"), [(3, 4), (5, 6)])
181181
82 82 | @pytest.mark.parametrize("d", [3,])
182-
83 83 | def test_multiple_decorators(a, b, c):
183-
84 84 | pass
182+
83 83 | @pytest.mark.parametrize(
183+
84 84 | "d",
184184

185185
PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
186186
|
187187
80 | @pytest.mark.parametrize("a", [1, 2])
188188
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
189189
| ^^^^^^ PT007
190190
82 | @pytest.mark.parametrize("d", [3,])
191-
83 | def test_multiple_decorators(a, b, c):
191+
83 | @pytest.mark.parametrize(
192192
|
193193
= help: Use `list` of `list` for parameter values
194194

@@ -199,16 +199,16 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
199199
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
200200
81 |+@pytest.mark.parametrize(("b", "c"), ([3, 4], (5, 6)))
201201
82 82 | @pytest.mark.parametrize("d", [3,])
202-
83 83 | def test_multiple_decorators(a, b, c):
203-
84 84 | pass
202+
83 83 | @pytest.mark.parametrize(
203+
84 84 | "d",
204204

205205
PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`
206206
|
207207
80 | @pytest.mark.parametrize("a", [1, 2])
208208
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
209209
| ^^^^^^ PT007
210210
82 | @pytest.mark.parametrize("d", [3,])
211-
83 | def test_multiple_decorators(a, b, c):
211+
83 | @pytest.mark.parametrize(
212212
|
213213
= help: Use `list` of `list` for parameter values
214214

@@ -219,5 +219,5 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
219219
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
220220
81 |+@pytest.mark.parametrize(("b", "c"), ((3, 4), [5, 6]))
221221
82 82 | @pytest.mark.parametrize("d", [3,])
222-
83 83 | def test_multiple_decorators(a, b, c):
223-
84 84 | pass
222+
83 83 | @pytest.mark.parametrize(
223+
84 84 | "d",

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
210210
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
211211
| ^^^^^^^^^^^^^^^^ PT007
212212
82 | @pytest.mark.parametrize("d", [3,])
213-
83 | def test_multiple_decorators(a, b, c):
213+
83 | @pytest.mark.parametrize(
214214
|
215215
= help: Use `list` of `tuple` for parameter values
216216

@@ -221,5 +221,5 @@ PT007.py:81:38: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
221221
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
222222
81 |+@pytest.mark.parametrize(("b", "c"), [(3, 4), (5, 6)])
223223
82 82 | @pytest.mark.parametrize("d", [3,])
224-
83 83 | def test_multiple_decorators(a, b, c):
225-
84 84 | pass
224+
83 83 | @pytest.mark.parametrize(
225+
84 84 | "d",

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap

+54-11
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
237237
80 |+@pytest.mark.parametrize("a", (1, 2))
238238
81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
239239
82 82 | @pytest.mark.parametrize("d", [3,])
240-
83 83 | def test_multiple_decorators(a, b, c):
240+
83 83 | @pytest.mark.parametrize(
241241

242242
PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
243243
|
244244
80 | @pytest.mark.parametrize("a", [1, 2])
245245
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
246246
| ^^^^^^ PT007
247247
82 | @pytest.mark.parametrize("d", [3,])
248-
83 | def test_multiple_decorators(a, b, c):
248+
83 | @pytest.mark.parametrize(
249249
|
250250
= help: Use `tuple` of `list` for parameter values
251251

@@ -256,16 +256,16 @@ PT007.py:81:39: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
256256
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
257257
81 |+@pytest.mark.parametrize(("b", "c"), ([3, 4], (5, 6)))
258258
82 82 | @pytest.mark.parametrize("d", [3,])
259-
83 83 | def test_multiple_decorators(a, b, c):
260-
84 84 | pass
259+
83 83 | @pytest.mark.parametrize(
260+
84 84 | "d",
261261

262262
PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
263263
|
264264
80 | @pytest.mark.parametrize("a", [1, 2])
265265
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
266266
| ^^^^^^ PT007
267267
82 | @pytest.mark.parametrize("d", [3,])
268-
83 | def test_multiple_decorators(a, b, c):
268+
83 | @pytest.mark.parametrize(
269269
|
270270
= help: Use `tuple` of `list` for parameter values
271271

@@ -276,17 +276,17 @@ PT007.py:81:47: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
276276
81 |-@pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
277277
81 |+@pytest.mark.parametrize(("b", "c"), ((3, 4), [5, 6]))
278278
82 82 | @pytest.mark.parametrize("d", [3,])
279-
83 83 | def test_multiple_decorators(a, b, c):
280-
84 84 | pass
279+
83 83 | @pytest.mark.parametrize(
280+
84 84 | "d",
281281

282282
PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
283283
|
284284
80 | @pytest.mark.parametrize("a", [1, 2])
285285
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
286286
82 | @pytest.mark.parametrize("d", [3,])
287287
| ^^^^ PT007
288-
83 | def test_multiple_decorators(a, b, c):
289-
84 | pass
288+
83 | @pytest.mark.parametrize(
289+
84 | "d",
290290
|
291291
= help: Use `tuple` of `list` for parameter values
292292

@@ -296,5 +296,48 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
296296
81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
297297
82 |-@pytest.mark.parametrize("d", [3,])
298298
82 |+@pytest.mark.parametrize("d", (3,))
299-
83 83 | def test_multiple_decorators(a, b, c):
300-
84 84 | pass
299+
83 83 | @pytest.mark.parametrize(
300+
84 84 | "d",
301+
85 85 | [("3", "4")],
302+
303+
PT007.py:85:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
304+
|
305+
83 | @pytest.mark.parametrize(
306+
84 | "d",
307+
85 | [("3", "4")],
308+
| ^^^^^^^^^^^^ PT007
309+
86 | )
310+
87 | @pytest.mark.parametrize(
311+
|
312+
= help: Use `tuple` of `list` for parameter values
313+
314+
Unsafe fix
315+
82 82 | @pytest.mark.parametrize("d", [3,])
316+
83 83 | @pytest.mark.parametrize(
317+
84 84 | "d",
318+
85 |- [("3", "4")],
319+
85 |+ (("3", "4"),),
320+
86 86 | )
321+
87 87 | @pytest.mark.parametrize(
322+
88 88 | "e",
323+
324+
PT007.py:89:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`
325+
|
326+
87 | @pytest.mark.parametrize(
327+
88 | "e",
328+
89 | [("3", "4"),],
329+
| ^^^^^^^^^^^^^ PT007
330+
90 | )
331+
91 | def test_multiple_decorators(a, b, c, d, e):
332+
|
333+
= help: Use `tuple` of `list` for parameter values
334+
335+
Unsafe fix
336+
86 86 | )
337+
87 87 | @pytest.mark.parametrize(
338+
88 88 | "e",
339+
89 |- [("3", "4"),],
340+
89 |+ (("3", "4"),),
341+
90 90 | )
342+
91 91 | def test_multiple_decorators(a, b, c, d, e):
343+
92 92 | pass

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap

+48-5
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ PT007.py:80:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
279279
80 |+@pytest.mark.parametrize("a", (1, 2))
280280
81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
281281
82 82 | @pytest.mark.parametrize("d", [3,])
282-
83 83 | def test_multiple_decorators(a, b, c):
282+
83 83 | @pytest.mark.parametrize(
283283

284284
PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
285285
|
286286
80 | @pytest.mark.parametrize("a", [1, 2])
287287
81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
288288
82 | @pytest.mark.parametrize("d", [3,])
289289
| ^^^^ PT007
290-
83 | def test_multiple_decorators(a, b, c):
291-
84 | pass
290+
83 | @pytest.mark.parametrize(
291+
84 | "d",
292292
|
293293
= help: Use `tuple` of `tuple` for parameter values
294294

@@ -298,5 +298,48 @@ PT007.py:82:31: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expect
298298
81 81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6)))
299299
82 |-@pytest.mark.parametrize("d", [3,])
300300
82 |+@pytest.mark.parametrize("d", (3,))
301-
83 83 | def test_multiple_decorators(a, b, c):
302-
84 84 | pass
301+
83 83 | @pytest.mark.parametrize(
302+
84 84 | "d",
303+
85 85 | [("3", "4")],
304+
305+
PT007.py:85:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
306+
|
307+
83 | @pytest.mark.parametrize(
308+
84 | "d",
309+
85 | [("3", "4")],
310+
| ^^^^^^^^^^^^ PT007
311+
86 | )
312+
87 | @pytest.mark.parametrize(
313+
|
314+
= help: Use `tuple` of `tuple` for parameter values
315+
316+
Unsafe fix
317+
82 82 | @pytest.mark.parametrize("d", [3,])
318+
83 83 | @pytest.mark.parametrize(
319+
84 84 | "d",
320+
85 |- [("3", "4")],
321+
85 |+ (("3", "4"),),
322+
86 86 | )
323+
87 87 | @pytest.mark.parametrize(
324+
88 88 | "e",
325+
326+
PT007.py:89:5: PT007 [*] Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
327+
|
328+
87 | @pytest.mark.parametrize(
329+
88 | "e",
330+
89 | [("3", "4"),],
331+
| ^^^^^^^^^^^^^ PT007
332+
90 | )
333+
91 | def test_multiple_decorators(a, b, c, d, e):
334+
|
335+
= help: Use `tuple` of `tuple` for parameter values
336+
337+
Unsafe fix
338+
86 86 | )
339+
87 87 | @pytest.mark.parametrize(
340+
88 88 | "e",
341+
89 |- [("3", "4"),],
342+
89 |+ (("3", "4"),),
343+
90 90 | )
344+
91 91 | def test_multiple_decorators(a, b, c, d, e):
345+
92 92 | pass

0 commit comments

Comments
 (0)