{"id":"ebf6886f6860904c","repo":"pytest-dev/pytest","slug":"expected-a-float-string-for-option-name-of-type","errorCode":null,"errorMessage":"Expected a float string for option {name} of type float, but got: {value!r}","messagePattern":"Expected a float string for option (.+?) of type float, but got: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":1937,"sourceCode":"            return shlex.split(value) if isinstance(value, str) else value\n        elif type == \"linelist\":\n            if isinstance(value, str):\n                return [t for t in map(lambda x: x.strip(), value.split(\"\\n\")) if t]\n            else:\n                return value\n        elif type == \"bool\":\n            return _strtobool(str(value).strip())\n        elif type == \"string\":\n            return value\n        elif type == \"int\":\n            if not isinstance(value, str):\n                raise TypeError(\n                    f\"Expected an int string for option {name} of type integer, but got: {value!r}\"\n                ) from None\n            return int(value)\n        elif type == \"float\":\n            if not isinstance(value, str):\n                raise TypeError(\n                    f\"Expected a float string for option {name} of type float, but got: {value!r}\"\n                ) from None\n            return float(value)\n        else:\n            return self._getini_unknown_type(name, type, value)\n\n    def _getini_toml(\n        self,\n        name: str,\n        canonical_name: str,\n        type: str,\n        value: object,\n        default: Any,\n    ):\n        \"\"\"Handle TOML config values with strict type validation and no coercion.\n\n        In TOML mode, values already have native types from TOML parsing.\n        We validate types match expectations exactly, including list items.","sourceCodeStart":1919,"sourceCodeEnd":1955,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L1919-L1955","documentation":"Raised by Config._getini_ini (config/__init__.py:1935-1939) for an option of type 'float' when, in INI mode, the value is not a str. Symmetric to the int case: float(value) is only valid on strings, and a non-str means the value bypassed the normal text-parsing path.","triggerScenarios":"Injecting a native float into an ini-mode float option via direct _inicfg mutation or a custom override path; calling _getini_ini with a non-str for a float-typed option.","commonSituations":"Programmatic config injection in conftest/plugin code; partial mocks in test suites for pytest itself; refactors that hand native floats to a path expecting strings.","solutions":["Pass float values as strings so float(value) coercion runs: '1.5' not 1.5.","Use the standard CLI / TOML path for float options instead of mutating _inicfg.","For TOML config, switch the option to toml mode where native floats are accepted directly (see error 55)."],"exampleFix":"# before\nconfig._inicfg['timeout'] = ConfigValue(value=1.5, ...)\n\n# after\nconfig._inicfg['timeout'] = ConfigValue(value='1.5', ...)","handlingStrategy":"validation","validationCode":"def coerce_float_str(value):\n    if not isinstance(value, str):\n        value = str(value)\n    float(value)\n    return value","typeGuard":"def is_float_str(value) -> bool:\n    if not isinstance(value, str):\n        return False\n    try:\n        float(value); return True\n    except ValueError:\n        return False","tryCatchPattern":"try:\n    config.getini(name)\nexcept (TypeError, ValueError):\n    # convert to a float string and reload","preventionTips":["Inject floats as strings into ini-mode config.","Use toml mode for native float support.","Avoid manual _inicfg mutation in plugins."],"tags":["config","ini","float-coercion","type-mismatch","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}