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

pytest-parametrize-values-wrong-type (PT007 ) unsafe fix fails if there is a list of only one item #10861

Closed
nyoungstudios opened this issue Apr 10, 2024 · 1 comment · Fixed by #10862
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@nyoungstudios
Copy link

Here is a minimal .ruff.toml file using 0.3.5:

line-length = 120

target-version = "py38"

lint.extend-select = [
    "W",  # whitespace
    "I",  # imports

    # pytest
    "PT001",  # pytest-fixture-incorrect-parentheses-style
    "PT006",  # pytest-parametrize-names-wrong-type
    "PT007",  # pytest-parametrize-values-wrong-type
    "PT025",  # pytest-erroneous-use-fixtures-on-fixture
    "PT026",  # pytest-use-fixtures-without-parameters
]

[ lint.isort ]

known-first-party = ["module"]

[ lint.flake8-pytest-style ]

fixture-parentheses = false
parametrize-names-type = "csv"
parametrize-values-row-type = "tuple"
parametrize-values-type = "tuple"

Here is the code snippet

import pytest
from pytest_mock import MockFixture

from module.sub import (
    get_value,
)


@pytest.fixture
def mock_check_output(mocker: MockFixture, output: bytes):
    return mocker.patch("subprocess.check_output", return_value=output)


@pytest.mark.parametrize(
    "output, expected_result",
    [(b"apple", "apple")],
)
def test_get_value(mock_check_output, expected_result):
    assert get_value() == expected_result
    mock_check_output.assert_called_once()

Running this command

ruff check path/to/file.py --fix --unsafe-fixes

outputs this error

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `path/to/file.py`, the rule codes PT007, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

path/to/file.py:16:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`
Found 1 error.
[*] 1 fixable with the --fix option.

However, changing the pytest parameterize code block to:

@pytest.mark.parametrize(
    "output, expected_result",
    [(b"apple", "apple"), (b"banana", "banana")],
)

allows the ruff command to run successfully. And successfully changes the parameterize code block to:

@pytest.mark.parametrize(
    "output, expected_result",
    ((b"apple", "apple"), (b"banana", "banana")),
)
@charliermarsh
Copy link
Member

Thanks!

@charliermarsh charliermarsh added bug Something isn't working fixes Related to suggested fixes for violations labels Apr 10, 2024
@charliermarsh charliermarsh self-assigned this Apr 10, 2024
charliermarsh added a commit that referenced this issue Apr 10, 2024
…trize-values-wrong-type` (#10862)

## Summary

This looks like a typo (without test coverage).

Closes #10861.
Glyphack pushed a commit to Glyphack/ruff that referenced this issue Apr 12, 2024
…trize-values-wrong-type` (astral-sh#10862)

## Summary

This looks like a typo (without test coverage).

Closes astral-sh#10861.
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
2 participants