Skip to content

[flake8-pytest-style] Avoid fixes for ambiguous argnames and argvalues combinations (PT006)#24776

Merged
ntBre merged 5 commits into
astral-sh:mainfrom
George-Ogden:pytest-single-parameters
Jun 1, 2026
Merged

[flake8-pytest-style] Avoid fixes for ambiguous argnames and argvalues combinations (PT006)#24776
ntBre merged 5 commits into
astral-sh:mainfrom
George-Ogden:pytest-single-parameters

Conversation

@George-Ogden
Copy link
Copy Markdown
Contributor

Fixes #24715 and related to #22441

Summary

This prevents changes that break code (almost certainly) in rule PT006.

Consider the following examples:

import pytest

TEST_CASES = [...]
@pytest.mark.parametrize(("number",), TEST_CASES)
def foo(number): ...

def generate_test_case():
    ...

@pytest.mark.parametrize(("number",), (generate_test_case(),))
def foo(number): ...

single_test_case = ...
@pytest.mark.parametrize(("number",), [single_test_case])
def foo(number): ...

Before this change, the argnames would be updated, which would probably break the test. After this change, no fix will be applied.

Test Plan

I added one test, but mostly fixed existing tests.

Do not adjust argnames when argvalues is not a sequence of tuples
@ntBre
Copy link
Copy Markdown
Contributor

ntBre commented Apr 22, 2026

Thanks for opening this, the changes aren't as involved as I feared. My main concern is that this decreases the usefulness of the rule if we're not offering a fix in more cases. I've approved the workflows so that we can get an ecosystem report and try to get some data on whether this removes more problems than it avoids desirable fixes.

@ntBre ntBre added the fixes Related to suggested fixes for violations label Apr 22, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 22, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Copy Markdown
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I tidied up some of the test changes, which reduced the size of the diff and made it easier to see the kinds of fixes that were removed. I think these were all cases where the fix was changing the behavior of the test and make sense not to offer a fix. I also moved the new test case into an mdtest.

@ntBre ntBre changed the title Remove breaking fixes for pytest singleton parameters [flake8-pytest-style] Avoid fixes for ambiguous argnames and argvalues combinations (PT006) Jun 1, 2026
@ntBre ntBre merged commit aa76512 into astral-sh:main Jun 1, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PT006 breaks when only one argname

2 participants