flake8-unused-arguments
flake8-unused-arguments copied to clipboard
Fixture is not used but needs to be included for some reasons
When a fixture is not used but needs to be included for some reasons, flake8-unused-arguments will rightfully issue a warning. For instance, a fixture setup a specific database state and another fixture include it to ensure database is in a specific state.
@pytest.fixture
def init_database():
"""Setup database state"""
...
@pytest.fixture
def add_element(init_database):
"""Insert element into the database"""
# init_database is never used.
...
Hacky fix
One could just disable "unused-argument" warning for this specific line like, so:
@pytest.fixture
def init_database():
"""Setup database state"""
...
@pytest.fixture
def add_element(init_database): # noqa
"""Insert element into the database"""
# init_database is never used.
...
But since it disables the warning for the whole line, any truly unused argument added later will not be reported
Better fix
An argument starting with an underscore is not subject to the "unused-argument" warning. Hence having your fixture name starting with an underscore fixes the warning.
@pytest.fixture
def _init_database():
"""Setup database state"""
...
@pytest.fixture
def add_element(_init_database):
"""Insert element into the database"""
# _init_database is never used.
...
Even better fix
Use a different name for the fixture and its implementation function, in order to avoid some other flake8-unused-arguments warnings:
@pytest.fixture(name='_init_database')
def fixture_init_database():
"""Setup database state"""
...
@pytest.fixture(name='add_element')
def fixture_add_element(_init_database):
"""Insert element into the database"""
# _init_database is never used.
...
Maksim, what action would you like me to take here?