pytest-dev/pytest · error · TypeError
{self.inipath}: config option '{name}' expects a string, got
Error message
{self.inipath}: config option '{name}' expects a string, got {value_type}: {value!r} What it means
Raised by Config._getini_toml (config/__init__.py:2017-2023) for a 'string'-typed option in TOML mode when the value is not a Python str. TOML preserves native types, so a bare int/bool/float/list where a string is required is rejected (no coercion, unlike INI mode).
Source
Thrown at src/_pytest/config/__init__.py:2020
# Expect an integer (but not bool, which is a subclass of int).
if not isinstance(value, int) or isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects an int, "
f"got {value_type}: {value!r}"
)
return value
elif type == "float":
# Expect a float or integer only.
if not isinstance(value, (float, int)) or isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a float, "
f"got {value_type}: {value!r}"
)
return value
elif type == "string":
# Expect a string.
if not isinstance(value, str):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a string, "
f"got {value_type}: {value!r}"
)
return value
else:
return self._getini_unknown_type(name, type, value)
def _getconftest_pathlist(
self, name: str, path: pathlib.Path
) -> list[pathlib.Path] | None:
try:
mod, relroots = self.pluginmanager._rget_with_confmod(name, path)
except KeyError:
return None
assert mod.__file__ is not None
modpath = pathlib.Path(mod.__file__).parent
values: list[pathlib.Path] = []
for relroot in relroots:View on GitHub (pinned to 98b357f69e)
Solutions
- Quote the value in TOML: x = "value".
- Watch for barewords that TOML parses as int/bool (8, true) and wrap them in quotes.
- Confirm the option's registered type is 'string' (or a Literal choice).
Example fix
# before (pyproject.toml) [tool.pytest.ini_options] minversion = 8 # after minversion = "8.0"
Defensive patterns
Strategy: validation
Validate before calling
def ensure_toml_str(value):
if not isinstance(value, str):
raise TypeError('string option in TOML must be a quoted string')
return value Type guard
def is_str(value) -> bool:
return isinstance(value, str) Try / catch
try:
config.getini(name)
except Exception:
# quote the value in pyproject.toml and reload Prevention
- Quote string values in TOML, especially ones that look numeric/boolean.
- Validate pyproject.toml pytest sections with a linter.
- Beware barewords (8, true) parsed as non-string types.
When it happens
Trigger: Setting a string option in pyproject.toml to an unquoted bareword that TOML parses as a number/bool, e.g. minversion = 8 instead of minversion = "8".
Common situations: Forgetting quotes around values that look numeric or boolean (e.g. minversion, markers); INI->TOML migration; treating TOML like a shell config.
Related errors
- {self.inipath}: config option '{name}' expects one of {_ini_
- {self.inipath}: config option '{name}' expects a string, got
- {self.inipath}: config option '{name}' expects a list for ty
- {self.inipath}: config option '{name}' expects a list for ty
- {self.inipath}: config option '{name}' expects a bool, got {
AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04).
Data as JSON: /data/errors/1c42c1aa25eb8c9e.json.
Report an issue: GitHub.