pytest-dev/pytest · error · TypeError

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

Error message

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

What it means

Raised by Config._getini_toml (config/__init__.py:2009-2015) for a 'float'-typed option in TOML mode when the value is neither a float nor an int — and explicitly rejects bool. ints are accepted (a native TOML int is a valid float), but strings/bools are not.

Source

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

            # 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}"
                )
            return value
        else:
            return self._getini_unknown_type(name, type, value)

    def _getconftest_pathlist(
        self, name: str, path: pathlib.Path
    ) -> list[pathlib.Path] | None:

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Use a bare TOML float: x = 1.5 (no quotes). A bare int (2) is also accepted.
  2. Remove quotes/convert booleans to the intended numeric value.
  3. Confirm the option is registered as 'float' and supply a numeric literal.

Example fix

# before (pyproject.toml)
[tool.pytest.ini_options]
faulthandler_timeout = "5.0"

# after
faulthandler_timeout = 5.0
Defensive patterns

Strategy: validation

Validate before calling

def ensure_toml_float(value):
    if not isinstance(value, (int, float)) or isinstance(value, bool):
        raise TypeError('float option in TOML must be a numeric literal')
    return value

Type guard

def is_native_number(value) -> bool:
    return isinstance(value, (int, float)) and not isinstance(value, bool)

Try / catch

try:
    config.getini(name)
except Exception:
    # supply a bare numeric literal and reload

Prevention

When it happens

Trigger: Setting a float option in pyproject.toml to a quoted string ("1.5"), a bool (true), or any non-numeric type.

Common situations: Quoting floats in TOML; using true/false; mistyping a numeric threshold; INI->TOML migration leaving strings.

Related errors


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