{"record":{"id":"20529329d4946228","repo":"locustio/locust","slug":"multiple-fixtures-found-for-parameter-name-r-in","errorCode":null,"errorMessage":"Multiple fixtures found for parameter {name!r} in {function.name}: {defs}","messagePattern":"Multiple fixtures found for parameter (.+?) in (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"locust/util/load_locustfile.py","lineNumber":128,"sourceCode":"        ],\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":110,"sourceCodeEnd":137,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/util/load_locustfile.py#L110-L137","documentation":"In locust's pytest integration, each test function's parameters must resolve to exactly one pytest fixture via fixturemanager.getfixturedefs. If a parameter matches more than one fixture definition (e.g. a fixture overridden in multiple scopes or duplicated via conftest/plugin chains), load_locustfile cannot pick one and raises this ValueError while building the PytestUser class.","triggerScenarios":"Running `locust -f locustfile.py` where the locustfile imports/loads pytest-style test functions and one function parameter has >1 matching fixture defs, e.g. the same fixture name defined in both conftest.py and the module, or via a plugin autouse fixture with the same name.","commonSituations":"Projects mixing pytest suites with locust load tests where conftest.py fixtures shadow module fixtures; installing plugins that register fixtures with common names (like 'client' or 'user'); copy-pasting fixture definitions into both conftest and test files.","solutions":["Rename one of the conflicting fixtures so each parameter maps to exactly one fixture","Remove the duplicated fixture definition (keep the conftest.py one and delete the module-level copy, or vice versa)","Use @pytest.fixture(autouse=False) scoping or parametrization restructuring to avoid duplicate names","Run `pytest --fixtures <file>` to list which fixture definitions match the parameter name and delete/shadow the extra one"],"exampleFix":"# before\ntests/conftest.py\n@pytest.fixture\ndef client(): ...\n\nlocustfile.py\n@pytest.fixture\ndef client(): ...\n\n# after\nlocustfile.py\n@pytest.fixture\ndef http_client(): ...  # renamed so 'client' resolves to a single fixture","handlingStrategy":"validation","validationCode":"import pytest\ndef ensure_unique_fixtures(path):\n    from _pytest.config import get_config, get_plugin_manager\n    cfg = get_config(); cfg.parse([str(path)]); cfg._preparse([], addopts=False)\n    fm = cfg.pluginmanager.get_plugin('funcmanage')\n    for name in {n for n in collect_param_names(path)}:\n        assert len(fm.getfixturedefs(name, None) or []) <= 1, f\"duplicate fixture: {name}\"","typeGuard":null,"tryCatchPattern":"try:\n    user_classes = load_locustfile(path)\nexcept ValueError as e:\n    if 'Multiple fixtures found' in str(e):\n        log.error('Duplicate fixture definitions; run `pytest --fixtures` to find them: %s', e)\n        sys.exit(2)\n    raise","preventionTips":["Define each fixture exactly once, ideally in conftest.py","Avoid generic fixture names like 'user' or 'client' that plugins may also register","Run `pytest --fixtures` when adding plugins to spot name collisions","Keep pytest fixtures out of the locustfile itself"],"tags":["pytest","fixtures","load-locustfile"],"backgroundTag":"ambiguous-fixture-parameter","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}