pytest-dev/pytest · error · TypeError

{self.inipath}: config option '{name}' expects a bool, got {

Error message

{self.inipath}: config option '{name}' expects a bool, got {value_type}: {value!r}

What it means

Raised by Config._getini_toml (config/__init__.py:1993-1999) for a 'bool'-typed option in TOML mode when the value is not a Python bool. TOML has a native boolean type, so pytest requires true/false; the strings "true"/"false" or 1/0 are rejected because they are not bool.

Source

Thrown at src/_pytest/config/__init__.py:1996

        elif type in {"args", "linelist"}:
            # Expect a list of strings.
            if not isinstance(value, list):
                raise TypeError(
                    f"{self.inipath}: config option '{name}' expects a list for type '{type}', "
                    f"got {value_type}: {value!r}"
                )
            for i, item in enumerate(value):
                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}"

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Use TOML native booleans: x = true (or false), unquoted.
  2. Remove quotes around the value.
  3. If you need 1/0/yes/no accepted, keep the option in pytest.ini where _strtobool coerces strings.

Example fix

# before (pyproject.toml)
[tool.pytest.ini_options]
cache_provider = "true"

# after
cache_provider = true
Defensive patterns

Strategy: validation

Validate before calling

def ensure_toml_bool(value):
    if not isinstance(value, bool):
        raise TypeError('bool option in TOML must be true/false')
    return value

Type guard

def is_native_bool(value) -> bool:
    return isinstance(value, bool)

Try / catch

try:
    config.getini(name)
except Exception:
    # set value to a native TOML true/false and reload

Prevention

When it happens

Trigger: Setting a bool option in pyproject.toml to a string ("true"), an int (1), or any non-bool type. Example: addopts = 1 for an option registered as bool.

Common situations: Quoting booleans in TOML (`x = "true"`); using 1/0 integers (valid in INI via _strtobool, rejected in TOML); copy-paste from INI without converting to native bool.

Related errors


AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04). Data as JSON: /data/errors/bb38990438f3f4fc.json. Report an issue: GitHub.