Skip to content
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

PT006 breaks test by removing tuple from parametrize #11243

Closed
Pebin opened this issue May 2, 2024 · 1 comment · Fixed by #14699
Closed

PT006 breaks test by removing tuple from parametrize #11243

Pebin opened this issue May 2, 2024 · 1 comment · Fixed by #14699
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@Pebin
Copy link

Pebin commented May 2, 2024

PT006 breaks test, removes tuple just from argnames but not from argvalues

@pytest.mark.parametrize(("thresholds",), [([0.6, 0.3],), ([],)])

is replaced as

@pytest.mark.parametrize("thresholds", [([0.6, 0.3],), ([],)])

so now thresholds contains tuple of list. Shouldn't the fix remove also the brackets inside so the result would be:

@pytest.mark.parametrize("thresholds", [[0.6, 0.3], []])

command:
ruff tests/test.py --fix

ruff 0.4.2, no special settings needed, python 3.9

@charliermarsh charliermarsh added bug Something isn't working fixes Related to suggested fixes for violations labels May 2, 2024
@jhbuhrman
Copy link

jhbuhrman commented Sep 18, 2024

This is a serious breakage; ruff --fix introduces an error.

The --fix option should also "fix" (i.e. de-tuple) the parameter value if it de-tuples the argnames parameter in case of a single parameter.

Apart from that, I find the obligatory (non-configurable) special case of tuple/list-less argnames in case of a single parameter quite questionable (if you later on would like to extend your test case with an additional parameter, you suddenly have to tuplify everything). I would prefer yet another configuration item that controls this quite opiniated preference for single parameter cases.

@dylwil3 dylwil3 added needs-mre Needs more information for reproduction and removed needs-mre Needs more information for reproduction labels Nov 10, 2024
MichaReiser pushed a commit that referenced this issue Dec 9, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
4 participants