locustio/locust · error · ValueError
Multiple fixtures found for parameter {name!r} in {function.
Error message
Multiple fixtures found for parameter {name!r} in {function.name}: {defs} What it means
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.
Source
Thrown at locust/util/load_locustfile.py:128
],
)
config._do_configure()
session = pytest.Session.from_config(config)
config.hook.pytest_sessionstart(session=session)
session.perform_collect()
config.hook.pytest_collection_modifyitems(session=session, config=config, items=session.items)
fm = session._fixturemanager
for function in session.items:
if isinstance(function, pytest.Function):
sig = inspect.signature(function.obj)
function.kwargs = {} # type: ignore[attr-defined]
for name in sig.parameters:
defs = fm.getfixturedefs(name, function)
if not defs:
raise ValueError(f"Could not find fixture for parameter {name!r} in {function.name}")
if len(defs) > 1:
raise ValueError(f"Multiple fixtures found for parameter {name!r} in {function.name}: {defs}")
function.fixturedef = defs[0] # type: ignore[attr-defined]
if not function.name in user_classes:
user_classes[function.name] = type(function.name, (PytestUser,), {})
user_classes[function.name].functions = []
user_classes[function.name].functions.append(function)
else:
pass # Skipping non-function item
return user_classes # type: ignore
View on GitHub (pinned to f391a716e1)
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
Example fix
# before tests/conftest.py @pytest.fixture def client(): ... locustfile.py @pytest.fixture def client(): ... # after locustfile.py @pytest.fixture def http_client(): ... # renamed so 'client' resolves to a single fixture
Defensive patterns
Strategy: validation
Validate before calling
import pytest
def ensure_unique_fixtures(path):
from _pytest.config import get_config, get_plugin_manager
cfg = get_config(); cfg.parse([str(path)]); cfg._preparse([], addopts=False)
fm = cfg.pluginmanager.get_plugin('funcmanage')
for name in {n for n in collect_param_names(path)}:
assert len(fm.getfixturedefs(name, None) or []) <= 1, f"duplicate fixture: {name}" Try / catch
try:
user_classes = load_locustfile(path)
except ValueError as e:
if 'Multiple fixtures found' in str(e):
log.error('Duplicate fixture definitions; run `pytest --fixtures` to find them: %s', e)
sys.exit(2)
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/20529329d4946228.
Report an issue: GitHub.