{"record":{"id":"e3ce51b277998d89","repo":"pytest-dev/pytest","slug":"fixture-argname-not-found","errorCode":null,"errorMessage":"fixture '{argname}' not found","messagePattern":"fixture '(.+?)' not found","errorType":"exception","errorClass":"FixtureLookupError","httpStatus":null,"severity":"error","filePath":"src/_pytest/fixtures.py","lineNumber":728,"sourceCode":"            return RequestFixtureDef(self)\n\n        # If we already finished computing a fixture by this name in this item,\n        # return it.\n        fixturedef = self._fixture_defs.get(argname)\n        if fixturedef is not None:\n            self._check_scope(fixturedef, fixturedef._scope)\n            return fixturedef\n\n        # Find the appropriate fixturedef.\n        fixturedefs = self._arg2fixturedefs.get(argname, None)\n        if fixturedefs is None:\n            # We arrive here because of a dynamic call to\n            # getfixturevalue(argname) which was naturally\n            # not known at parsing/collection time.\n            fixturedefs = self._fixturemanager.getfixturedefs(argname, self._pyfuncitem)\n        # No fixtures defined with this name.\n        if fixturedefs is None:\n            raise FixtureLookupError(argname, self)\n        # The are no fixtures with this name applicable for the function.\n        if not fixturedefs:\n            raise FixtureLookupError(argname, self)\n\n        # A fixture may override another fixture with the same name, e.g. a\n        # fixture in a module can override a fixture in a conftest, a fixture in\n        # a class can override a fixture in the module, and so on.\n        # An overriding fixture can request its own name (possibly indirectly);\n        # in this case it gets the value of the fixture it overrides, one level\n        # up.\n        # Check how many `argname`s deep we are, and take the next one.\n        # `fixturedefs` is sorted from furthest to closest, so use negative\n        # indexing to go in reverse.\n        index = -1\n        for request in self._iter_chain():\n            if request.fixturename == argname:\n                index -= 1\n        # If already consumed all of the available levels, fail.","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/fixtures.py#L710-L746","documentation":"FixtureLookupError is pytest's signal that a fixture name could not be resolved for the current test. The short message 'fixture {argname} not found' is the headline; the full FixtureLookupError formats a detailed report (available fixtures, misspelled suggestions, line numbers) when rendered. It is raised both at static collection time (param/signature resolution) and at dynamic getfixturevalue() time.","triggerScenarios":"A test or fixture referencing a fixture name that is not defined in the test module, any conftest.py, or an installed plugin; a typo in the fixture name; the fixture lives in a conftest that is not on the path for this test; requesting a fixture that is parametrized out of scope; a conftest with a syntax/import error preventing fixture registration.","commonSituations":"Misspelled fixture name; conftest.py import failure (a different error masks the fixture); fixture defined in a plugin that is not installed or enabled; moving a test out of a package whose conftest defined the fixture; scope/parametrize mismatch leaving no applicable fixturedef.","solutions":["Check the spelling of the fixture name against its definition (and against the 'available fixtures' list in the rendered error).","Ensure the fixture is defined in the test module, a conftest.py in the right directory, or an installed/importable plugin.","If the fixture is in a plugin, confirm the plugin is installed and enabled (pytest --trace-config or pip show).","If the fixture is in a conftest, make sure that conftest imports cleanly (fix any ImportError shown earlier in the run).","For dynamic lookups, verify the fixture name is registered for this test's path via pytest --fixtures."],"exampleFix":"// before\n@pytest.fixture\ndef usr():\n    return {}\n\ndef test_user(user):   # typo: 'user' vs 'usr'\n    assert user\n// after\n@pytest.fixture\ndef user():\n    return {}\n\ndef test_user(user):\n    assert user","handlingStrategy":"validation","validationCode":"def fixture_exists(request, argname: str) -> bool:\n    defs = request._fixturemanager.getfixturedefs(argname, request._pyfuncitem)\n    return bool(defs)\n\nif not fixture_exists(request, 'myfix'):\n    pytest.skip('myfix not available for this test')","typeGuard":"null","tryCatchPattern":"import pytest\n\ntry:\n    val = request.getfixturevalue('maybe_missing')\nexcept pytest.FixtureLookupError:\n    val = None","preventionTips":["Keep fixture names consistent; use a project-wide prefix for shared fixtures.","Run 'pytest --fixtures' to confirm available fixtures for a test path.","Fix conftest import errors first - they silently disable fixtures defined later.","Define widely used fixtures in conftest.py at the right directory level."],"tags":["fixtures","lookup","testing","conftest"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}