Skip to content

False Positive W0621: Redefining name %r from outer scope when using pytest fixtures #6531

Open
@orSolocate

Description

@orSolocate

Bug description

Bug opened from SO issue

Testcase:

# test_wallet.py

@pytest.fixture
def my_wallet():
    '''Returns a Wallet instance with a zero balance'''
    return Wallet()

@pytest.mark.parametrize("earned,spent,expected", [
    (30, 10, 20),
    (20, 2, 18),
])
def test_transactions(my_wallet, earned, spent, expected):
    my_wallet.add_cash(earned)
    my_wallet.spend_cash(spent)
    assert my_wallet.balance == expected

They discuss a workaround to avoid the error and also a method of disabling the checker but this bug issue is about actually fixing it in Pylint, or at least discussing it.

Configuration

No response

Pylint output

`W0621: Redefining name %r from outer scope (line %s)'`

Expected behavior

The Pylint message should recognize this situation of pytest fixture decorator and don't raise a message.

Pylint version

pylint 2.8.4
astroid 2.5.8
Python 3.7.5

OS / Environment

Windows

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions