pytest-dev/pytest · error · ValueError
{name}
Error message
{name} What it means
Raised by CallSpec.getparam when the requested fixture/parameter name is not present in the CallSpec's params mapping. The exception message is just the missing name (a ValueError). This is an internal API used by pytest's fixture machinery to resolve a parameter value for a given argname within a specific callspec.
Source
Thrown at src/_pytest/python.py:1212
raise nodes.Collector.CollectError(
f"{nodeid}: duplicate parametrization of {arg!r}"
)
params[arg] = val
indices[arg] = param_index
arg2scope[arg] = scope
return CallSpec(
params=params,
indices=indices,
_arg2scope=arg2scope,
_idlist=self._idlist if id is HIDDEN_PARAM else [*self._idlist, id],
marks=[*self.marks, *normalize_mark_list(marks)],
)
def getparam(self, name: str) -> object:
try:
return self.params[name]
except KeyError as e:
raise ValueError(name) from e
@property
def id(self) -> str:
return "-".join(self._idlist)
if TYPE_CHECKING:
# Deprecated alias kept for type checkers; runtime access goes through __getattr__.
CallSpec2 = CallSpec
def get_direct_param_fixture_func(request: FixtureRequest) -> Any:
return request.param
class DirectParamFixtureDef(FixtureDef[FixtureValue]):
"""A custom FixtureDef for direct parametrization fixtures.
View on GitHub (pinned to 98b357f69e)
Solutions
- Check 'name in callspec.params' before calling getparam.
- Use callspec.params.get(name, default) instead of getparam when absence is possible.
- Verify the argname spelling matches the parametrize declaration.
Example fix
// before
val = callspec.getparam("usrname") # typo
// after
if "username" in callspec.params:
val = callspec.getparam("username")
else:
val = None Defensive patterns
Strategy: validation
Validate before calling
name = "username"
if name in callspec.params:
val = callspec.getparam(name)
else:
val = callspec.params.get(name) Try / catch
try:
val = callspec.getparam(name)
except ValueError:
val = None Prevention
- Check membership in callspec.params before getparam.
- Prefer callspec.params.get(name) when absence is acceptable.
- Keep argname spellings consistent with parametrize declarations.
When it happens
Trigger: Calling callspec.getparam('some_name') where 'some_name' was not part of the parametrize call that produced this callspec, or where the param was provided indirectly and not stored in params.
Common situations: Plugin or fixture code that introspects CallSpec objects and asks for an argname that doesn't exist for the current test; indirect parametrization where the name was misregistered; typos in argname lookups.
Related errors
- Empty parameter set in '{func.__name__}' at line {lineno + 1
- pytest.param cannot add pytest.mark.usefixtures; see https:/
- Expected id to be a string or a `pytest.HIDDEN_PARAM` sentin
- Unrecognized runpytest option: {self._method}
- Unknown parametrize_long_str_id_strategy: {value!r}. Valid v
AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04).
Data as JSON: /data/errors/9b0393bb9627a95b.json.
Report an issue: GitHub.