-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
pytest-parametrize-names-wrong-type (PT006)
to edit both `argna…
…mes` 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
- Loading branch information
Showing
9 changed files
with
901 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT006_and_PT007.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pytest | ||
|
||
@pytest.mark.parametrize(("param",), [[1], [2]]) | ||
def test_PT006_and_PT007_do_not_conflict(param): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...test_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT006_and_PT007.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs | ||
snapshot_kind: text | ||
--- | ||
PT006_and_PT007.py:3:26: PT006 [*] Wrong type passed to first argument of `pytest.mark.parametrize`; expected `str` | ||
| | ||
1 | import pytest | ||
2 | | ||
3 | @pytest.mark.parametrize(("param",), [[1], [2]]) | ||
| ^^^^^^^^^^ PT006 | ||
4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 | ... | ||
| | ||
= help: Use a string for the first argument | ||
|
||
ℹ Safe fix | ||
1 1 | import pytest | ||
2 2 | | ||
3 |-@pytest.mark.parametrize(("param",), [[1], [2]]) | ||
3 |+@pytest.mark.parametrize("param", [1, 2]) | ||
4 4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 5 | ... | ||
|
||
PT006_and_PT007.py:3:39: PT007 [*] Wrong values type in `pytest.mark.parametrize` expected `list` of `tuple` | ||
| | ||
1 | import pytest | ||
2 | | ||
3 | @pytest.mark.parametrize(("param",), [[1], [2]]) | ||
| ^^^ PT007 | ||
4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 | ... | ||
| | ||
= help: Use `list` of `tuple` for parameter values | ||
|
||
ℹ Unsafe fix | ||
1 1 | import pytest | ||
2 2 | | ||
3 |-@pytest.mark.parametrize(("param",), [[1], [2]]) | ||
3 |+@pytest.mark.parametrize(("param",), [(1,), [2]]) | ||
4 4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 5 | ... | ||
|
||
PT006_and_PT007.py:3:44: PT007 [*] Wrong values type in `pytest.mark.parametrize` expected `list` of `tuple` | ||
| | ||
1 | import pytest | ||
2 | | ||
3 | @pytest.mark.parametrize(("param",), [[1], [2]]) | ||
| ^^^ PT007 | ||
4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 | ... | ||
| | ||
= help: Use `list` of `tuple` for parameter values | ||
|
||
ℹ Unsafe fix | ||
1 1 | import pytest | ||
2 2 | | ||
3 |-@pytest.mark.parametrize(("param",), [[1], [2]]) | ||
3 |+@pytest.mark.parametrize(("param",), [[1], (2,)]) | ||
4 4 | def test_PT006_and_PT007_do_not_conflict(param): | ||
5 5 | ... |
Oops, something went wrong.