pytest-dev/pytest · error · UsageError
Unknown parametrize_long_str_id_strategy: {value!r}. Valid v
Error message
Unknown parametrize_long_str_id_strategy: {value!r}. Valid values: {', '.join(sorted(_LONG_STR_STRATEGIES))} What it means
Raised as UsageError by IdMaker._get_long_str_strategy when the ini option 'parametrize_long_str_id_strategy' has a value not in the allowed set {'short','sha256','legacy','disallow'}. This option controls how pytest generates test IDs for parametrized values that are long strings/bytes (>100 chars). An invalid value means config parsing accepted it but it is semantically unknown.
Source
Thrown at src/_pytest/python.py:1041
idval = self._idval_from_hook(val, argname)
if idval is not None:
return idval
if isinstance(val, str | bytes):
idval = self._apply_long_str_strategy(val, argname, idx)
if idval is not None:
return idval
else:
idval = self._idval_from_value(val)
if idval is not None:
return idval
return self._idval_from_argname(argname, idx)
def _get_long_str_strategy(self) -> LongStrIdStrategy:
if not self.config:
return "short"
value = self.config.getini("parametrize_long_str_id_strategy")
if value not in _LONG_STR_STRATEGIES:
raise UsageError(
f"Unknown parametrize_long_str_id_strategy: {value!r}. "
f"Valid values: {', '.join(sorted(_LONG_STR_STRATEGIES))}"
)
return cast(LongStrIdStrategy, value)
def _apply_long_str_strategy(
self, val: str | bytes, argname: str, idx: int
) -> str | None:
"""Apply the configured strategy for long str/bytes parameter values.
Only used for auto-generated IDs (not explicit ids=[...] or
pytest.param(id=...)).
"""
if len(val) <= 100:
return _ascii_escaped_by_config(val, self.config)
match self._get_long_str_strategy():
case "legacy":
return _ascii_escaped_by_config(val, self.config)View on GitHub (pinned to 98b357f69e)
Solutions
- Set the option to one of: 'short', 'sha256', 'legacy', or 'disallow'.
- Remove the option to fall back to the default ('short').
- Check the installed pytest version's docs for the current valid values.
Example fix
// before (pyproject.toml) [tool.pytest.ini_options] parametrize_long_str_id_strategy = "hash" // after [tool.pytest.ini_options] parametrize_long_str_id_strategy = "sha256"
Defensive patterns
Strategy: validation
Validate before calling
VALID = {"short", "sha256", "legacy", "disallow"}
val = config.getini("parametrize_long_str_id_strategy")
if val is not None and val not in VALID:
raise SystemExit(f"parametrize_long_str_id_strategy must be one of {sorted(VALID)}") Prevention
- Use only documented strategy names.
- Remove the option to rely on the default.
- Re-check valid values after upgrading pytest.
When it happens
Trigger: Setting parametrize_long_str_id_strategy to a typo or unsupported string (e.g. 'none', 'hash', 'truncate') in pyproject.toml [tool.pytest.ini_options], pytest.ini, or tox.ini, then running any parametrized test.
Common situations: Misspelling the strategy name; carrying over a config from a plugin that defined custom strategies; using a value from an outdated docs page.
Related errors
- name is not allowed to contain path separators
- relative tolerance for a scalar value must be an int, float
- expected value must support abs(...) when relative tolerance
- absolute tolerance for a scalar value must be an int, float
- absolute tolerance can't be negative: {absolute_tolerance}
AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04).
Data as JSON: /data/errors/4f3bf2b479f55d5a.json.
Report an issue: GitHub.