pytest-dev/pytest · error · TypeError
{self.inipath}: config option '{name}' expects an int, got {
Error message
{self.inipath}: config option '{name}' expects an int, got {value_type}: {value!r} What it means
Raised by Config._getini_toml (config/__init__.py:2001-2007) for an 'int'-typed option in TOML mode when the value is not an int — and explicitly rejects bool, because bool is a subclass of int in Python (`isinstance(True, int)` is True), so the guard uses `not isinstance(value, int) or isinstance(value, bool)`.
Source
Thrown at src/_pytest/config/__init__.py:2004
if not isinstance(item, str):
item_type = builtins.type(item).__name__
raise TypeError(
f"{self.inipath}: config option '{name}' expects a list of strings, "
f"but item at index {i} is {item_type}: {item!r}"
)
return list(value)
elif type == "bool":
# Expect a boolean.
if not isinstance(value, bool):
raise TypeError(
f"{self.inipath}: config option '{name}' expects a bool, "
f"got {value_type}: {value!r}"
)
return value
elif type == "int":
# 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}"View on GitHub (pinned to 98b357f69e)
Solutions
- Use a bare TOML integer: x = 2 (no quotes).
- If a bool was intended, change the option's registered type to 'bool'.
- Ensure floats are not used where ints are required (truncate/convert at the source).
Example fix
# before (pyproject.toml) verbosity_test_cases = "2" # after verbosity_test_cases = 2
Defensive patterns
Strategy: validation
Validate before calling
def ensure_toml_int(value):
if not isinstance(value, int) or isinstance(value, bool):
raise TypeError('int option in TOML must be a bare integer')
return value Type guard
def is_native_int(value) -> bool:
return isinstance(value, int) and not isinstance(value, bool) Try / catch
try:
config.getini(name)
except Exception:
# convert to a bare TOML integer and reload Prevention
- Use bare unquoted integers in TOML.
- Never substitute true/false for an int option.
- Remember bool is an int subclass — the guard explicitly excludes it.
When it happens
Trigger: Setting an int option in pyproject.toml to a string ("2"), a float (2.0), or a bool (true). A native TOML integer is required.
Common situations: Quoting ints in TOML; passing a float where an int is expected; accidentally using true/false for an int flag; INI->TOML migration leaving values as strings.
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/c78ca14ac0917c00.json.
Report an issue: GitHub.