{"record":{"id":"71c92364f424e5db","repo":"locustio/locust","slug":"could-not-find-fixture-for-parameter-name-r-in","errorCode":null,"errorMessage":"Could not find fixture for parameter {name!r} in {function.name}","messagePattern":"Could not find fixture for parameter (.+?) in (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"locust/util/load_locustfile.py","lineNumber":126,"sourceCode":"            \"-s\",  # dont capture stdin (locust uses it for opening a browser and other input events)\n            path,\n        ],\n    )\n    config._do_configure()\n    session = pytest.Session.from_config(config)\n    config.hook.pytest_sessionstart(session=session)\n    session.perform_collect()\n    config.hook.pytest_collection_modifyitems(session=session, config=config, items=session.items)\n    fm = session._fixturemanager\n\n    for function in session.items:\n        if isinstance(function, pytest.Function):\n            sig = inspect.signature(function.obj)\n            function.kwargs = {}  # type: ignore[attr-defined]\n            for name in sig.parameters:\n                defs = fm.getfixturedefs(name, function)\n                if not defs:\n                    raise ValueError(f\"Could not find fixture for parameter {name!r} in {function.name}\")\n                if len(defs) > 1:\n                    raise ValueError(f\"Multiple fixtures found for parameter {name!r} in {function.name}: {defs}\")\n                function.fixturedef = defs[0]  # type: ignore[attr-defined]\n            if not function.name in user_classes:\n                user_classes[function.name] = type(function.name, (PytestUser,), {})\n                user_classes[function.name].functions = []\n            user_classes[function.name].functions.append(function)\n        else:\n            pass  # Skipping non-function item\n    return user_classes  # type: ignore\n","sourceCodeStart":108,"sourceCodeEnd":137,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/util/load_locustfile.py#L108-L137","documentation":"When loading a locustfile via pytest (PytestUser), each test function's parameters must be resolvable to exactly one pytest fixture. If fixturemanager.getfixturedefs returns none for a parameter, ValueError is raised.","triggerScenarios":"A pytest-style user test function declares a parameter that matches no fixture (not defined, autouse-only mismatch, or defined in a non-imported plugin/conftest).","commonSituations":"Typos in fixture names; fixtures defined in a conftest.py outside the collection scope; missing plugin; parametrized fixtures yielding multiple defs (separate error).","solutions":["Define the missing fixture (in the locustfile or an imported conftest.py)","Fix the parameter name typo to match an existing fixture","Install/import the plugin providing the fixture","Ensure exactly one fixture matches the parameter name"],"exampleFix":"// before\ndef test_login(user_client):\n    ...  # no fixture named user_client\n// after\n@pytest.fixture\ndef user_client():\n    return ...\n\ndef test_login(user_client):\n    ...","handlingStrategy":"validation","validationCode":"import pytest\nfor p in inspect.signature(test_fn).parameters:\n    assert fm.getfixturedefs(p, test_fn), f\"Missing fixture {p}\"","typeGuard":null,"tryCatchPattern":"try:\n    load_locustfile_pytest(path)\nexcept ValueError as e:\n    logging.error(\"Fixture problem in locustfile: %s\", e)","preventionTips":["Define fixtures in the locustfile or an in-scope conftest.py","Keep fixture names distinct (avoid multi-match ambiguity)","Keep pytest plugins installed in the environment"],"tags":["python","locust","pytest","fixtures"],"backgroundTag":"fixture-not-found","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}