Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PT006: ignores parametrize markers on classes #2955

Description

@bastimeyer

before

import pytest


@pytest.mark.parametrize("foo,bar", [(1, 2), (3, 4)])
class Foo:
    def test_foo(self, foo: int, bar: int):
        assert foo < bar


@pytest.mark.parametrize("foo,bar", [(1, 2), (3, 4)])
def test_bar(foo: int, bar: int):
    assert foo < bar

lint & fix

$ ruff --version
ruff 0.0.247

$ ruff --select PT006 PT006.py 
PT006.py:10:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`
Found 1 error.
[*] 1 potentially fixable with the --fix option.

$ ruff --select PT006 --fix PT006.py
Found 1 error (1 fixed, 0 remaining).

after

import pytest


@pytest.mark.parametrize("foo,bar", [(1, 2), (3, 4)])
class Foo:
    def test_foo(self, foo: int, bar: int):
        assert foo < bar


@pytest.mark.parametrize(("foo", "bar"), [(1, 2), (3, 4)])
def test_bar(foo: int, bar: int):
    assert foo < bar

expected

import pytest


@pytest.mark.parametrize(("foo", "bar"), [(1, 2), (3, 4)])
class Foo:
    def test_foo(self, foo: int, bar: int):
        assert foo < bar


@pytest.mark.parametrize(("foo", "bar"), [(1, 2), (3, 4)])
def test_bar(foo: int, bar: int):
    assert foo < bar

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions