You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A fixture with autouse set to False will always be used if it overrides a fixture with autouse set to True #3225
Include a detailed description of the bug or suggestion
I took a look at pytest's source code and it looks like pytest records the names of all fixtures with autouse set to True. It then uses this list to determine which fixtures to use, even if the overriding fixture has autouse set to False.
pytest and operating system versions
platform linux2 -- Python 2.7.13, pytest-3.4.0, py-1.5.2, pluggy-0.6.0
I've encountered what may be another manifestation of this bug, only with parametrization. I'm doing some dynamic fixture creation based on command-line options. An autouse=True session fixture takes this fixture as an argument:
def pytest_configure(config):
class DynamicFixturePlugin2(object):
@pytest.fixture(scope='session', params=['foo, 'bar'] if config.getoption('--foo') else [''])
def baz(self, request):
return request.param
config.pluginmanager.register(DynamicFixturePlugin2(), 'baz-fixture')
I realized that I accidentally created a test that uses that same name as a parameter.
This test just so happened to be the first test in the file it was in. If I then invoke pytest with this file as the first item in a list of test files and that test is the first test in that file, then I get the following error:
ScopeMismatch: You tried to access the 'function' scoped fixture 'baz' with a 'session' scoped request object, involved factories
conftest.py:141: def autouse_fixture_that_depends_on_dynamic_fixture(request, baz, ...)
If it's not related, tell me and I'll file a separate bug.
Activity
ceridwen commentedon Mar 12, 2018
I've encountered what may be another manifestation of this bug, only with parametrization. I'm doing some dynamic fixture creation based on command-line options. An
autouse=Truesession fixture takes this fixture as an argument:I realized that I accidentally created a test that uses that same name as a parameter.
This test just so happened to be the first test in the file it was in. If I then invoke pytest with this file as the first item in a list of test files and that test is the first test in that file, then I get the following error:
If it's not related, tell me and I'll file a separate bug.
jbbqqf commentedon May 9, 2026