pytest-dev/pytest · error · UsageError
Unknown parametrize_long_str_id_strategy
Error message
Unknown parametrize_long_str_id_strategy: {value!r}. Valid values: {', '.join(sorted(_LONG_STR_STRATEGIES))} What it means
Thrown by Metafunc._get_long_str_strategy() when the ini value `parametrize_long_str_id_strategy` is not one of the recognized literals: 'short', 'sha256', 'legacy', 'disallow'. It guards config typos before they affect parametrize id generation.
Solutions
- Set the value to one of: short, sha256, legacy, disallow (lowercase, exact).
- Remove the ini key to fall back to the default ('short').
- Check for typos and trailing whitespace in the ini value.
Example fix
// before - pytest.ini [pytest] parametrize_long_str_id_strategy = SHA-256 // after [pytest] parametrize_long_str_id_strategy = sha256
Defensive patterns
Strategy: validation
Validate before calling
valid = {'short', 'sha256', 'legacy', 'disallow'}
value = config.getini('parametrize_long_str_id_strategy')
if value not in valid:
raise ValueError(f'bad strategy {value!r}, choose from {sorted(valid)}') Type guard
def is_valid_strategy(v: object) -> bool:
return v in {'short', 'sha256', 'legacy', 'disallow'} Prevention
- Use lowercase exact spellings: short, sha256, legacy, disallow.
- Remove the ini key to use the default rather than guessing.
- Re-check valid values after pytest upgrades.
When it happens
Trigger: Setting parametrize_long_str_id_strategy = sha in pytest.ini (truncated); a typo like 'sha-256' or 'SHA256' (case-sensitive); an old config from a pytest version that supported a different value set.
Common situations: Upgrading pytest and finding the strategy name changed; copy-paste from docs with a typo; case mismatch.
Related errors
- error raised while trying to determine id of parameter
- ids must be a callable or an iterable
- ' ' is not recognized as a logging level name for ' '…
- Missing required plugins
- must be a directory, given
AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11).
Data as JSON: /api/errors/4f3bf2b479f55d5a.
Report an issue: GitHub.
Appendix: 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 0d6fbdeffa)