When a fixture is not used but needs to be included for some reasons, pylint 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.
...
It's tempting to use @pytest.mark.usefixtures()
decorator but it cannot be used on fixtures.
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): #pylint: disable=W0613
"""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 by pylint.
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.
...
Use a different name for the fixture and its implementation function, in order to avoid some other pylint 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.
...