-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pytest-parametrize-names-wrong-type (PT006)
to edit both argnames
and argvalues
if both of them are single-element tuples/lists
#14699
Conversation
|
I'm sure you're right, but can you expand on why that's a problem? (Should we not be raising a diagnostic at all?) |
@charliermarsh Thanks for the comment!
This is another option. |
I just found #11243. Should we unpack each item in |
In this case, would this be correct?
With the comma inside the string? I don't know enough about pytest. |
@charliermarsh Let me check. import pytest
@pytest.mark.parametrize("x,", [(1,), (2,)])
def test_foo(x):
assert isinstance(x, int)
|
Source of the relevant pytest code According to the rule. How should a user rewrite your example?
|
@pytest.mark.parametrize(("x",), [(1,), (2,)])
def test_foo(x):
... should be rewritten to: @pytest.mark.parametrize("x", [1, 2])
def test_foo(x):
...
# I'd prefer this style because I don't need to wonder what x is (tuple vs. int) Both (I implemented a fix to fix |
pytest-parametrize-names-wrong-type (PT006)
not to suggest a fix if both argnames
and argvalues
are single-element sequencespytest-parametrize-names-wrong-type (PT006)
to edit argnames
and argvalues
as a fix
pytest-parametrize-names-wrong-type (PT006)
to edit argnames
and argvalues
as a fixpytest-parametrize-names-wrong-type (PT006)
to edit both argnames
and argvalues
if both of them are single-element tuples/lists
That sounds great. I'll have a look when you push the change |
crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs
Outdated
Show resolved
Hide resolved
// def test_foo(x): | ||
// assert isinstance(x, int) # fails because `x` is a tuple, not an int | ||
// ``` | ||
unpack_single_element_items(checker, argvalues), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add a test to ensure this doesn't conflict with PT007 which may also edit argvalues
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a great idea if we're concerned about whether the rules play nicely together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser Manually confirmed PT006 and PT007 don't conflicts:
> cargo run -p ruff -- check --no-cache --select PT007,PT006 a.py --unsafe-fixes --fix
--- a.py
+++ a.py
@@ -1,6 +1,6 @@
import pytest
-@pytest.mark.parametrize(("param",), [[1], [2], [3]])
+@pytest.mark.parametrize("param", [1, 2, 3])
def test_foo(param):
...
Would fix 1 error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case for this.
// def test_foo(x): | ||
// assert isinstance(x, int) # fails because `x` is a tuple, not an int | ||
// ``` | ||
unpack_single_element_items(checker, argvalues), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a great idea if we're concerned about whether the rules play nicely together.
crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thank you for following it thourgh
Summary
Close #11243. Fix
pytest-parametrize-names-wrong-type (PT006)
to edit bothargnames
andargvalues
if both of them are single-element tuples/lists.Test Plan
New test cases