mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Fix pytest-parametrize-names-wrong-type (PT006)
to edit both argnames
and argvalues
if both of them are single-element tuples/lists (#14699)
## Summary Close #11243. Fix `pytest-parametrize-names-wrong-type (PT006)` to edit both `argnames` and `argvalues` if both of them are single-element tuples/lists. ```python # Before fix @pytest.mark.parametrize(("x",), [(1,), (2,)]) def test_foo(x): ... # After fix: @pytest.mark.parametrize("x", [1, 2]) def test_foo(x): ... ``` ## Test Plan New test cases
This commit is contained in:
parent
8df4983057
commit
3d9ac535e9
9 changed files with 901 additions and 16 deletions
|
@ -81,3 +81,78 @@ def test_not_decorator(param1, param2):
|
|||
@pytest.mark.parametrize(argnames=("param1,param2"), argvalues=[(1, 2), (3, 4)])
|
||||
def test_keyword_arguments(param1, param2):
|
||||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("param",), [(1,), (2,)])
|
||||
def test_single_element_tuple(param):
|
||||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("param",), [[1], [2]])
|
||||
def test_single_element_list(param):
|
||||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("param",), [[1], [2]])
|
||||
def test_single_element_list(param):
|
||||
...
|
||||
|
||||
|
||||
# Unsafe fix
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
# comment
|
||||
"param",
|
||||
),
|
||||
[[1], [2]],
|
||||
)
|
||||
def test_comment_in_argnames(param):
|
||||
...
|
||||
|
||||
# Unsafe fix
|
||||
@pytest.mark.parametrize(
|
||||
("param",),
|
||||
[
|
||||
(
|
||||
# comment
|
||||
1,
|
||||
),
|
||||
(2,),
|
||||
],
|
||||
)
|
||||
def test_comment_in_argvalues(param):
|
||||
...
|
||||
|
||||
|
||||
# Safe fix
|
||||
@pytest.mark.parametrize(
|
||||
("param",),
|
||||
[
|
||||
(1,),
|
||||
# comment
|
||||
(2,),
|
||||
],
|
||||
)
|
||||
def test_comment_between_argvalues_items(param):
|
||||
...
|
||||
|
||||
|
||||
# A fix should be suggested for `argnames`, but not for `argvalues`.
|
||||
@pytest.mark.parametrize(
|
||||
("param",),
|
||||
[
|
||||
(1,),
|
||||
(2, 3),
|
||||
],
|
||||
)
|
||||
def test_invalid_argvalues(param):
|
||||
"""
|
||||
pytest throws the following error for this test:
|
||||
------------------------------------------------
|
||||
a.py::test_comment_between_argvalues_items: in "parametrize" the number of names (1):
|
||||
('param',)
|
||||
must be equal to the number of values (2):
|
||||
(2, 3)
|
||||
------------------------------------------------
|
||||
"""
|
||||
...
|
||||
|
|
5
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT006_and_PT007.py
vendored
Normal file
5
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT006_and_PT007.py
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import pytest
|
||||
|
||||
@pytest.mark.parametrize(("param",), [[1], [2]])
|
||||
def test_PT006_and_PT007_do_not_conflict(param):
|
||||
...
|
Loading…
Add table
Add a link
Reference in a new issue