{"record":{"id":"bb38990438f3f4fc","repo":"pytest-dev/pytest","slug":"self-inipath-config-option-name-expects-a-b","errorCode":null,"errorMessage":"{self.inipath}: config option '{name}' expects a bool, got {value_type}: {value!r}","messagePattern":"(.+?): config option '(.+?)' expects a bool, got (.+?): (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":1996,"sourceCode":"        elif type in {\"args\", \"linelist\"}:\n            # Expect a list of strings.\n            if not isinstance(value, list):\n                raise TypeError(\n                    f\"{self.inipath}: config option '{name}' expects a list for type '{type}', \"\n                    f\"got {value_type}: {value!r}\"\n                )\n            for i, item in enumerate(value):\n                if not isinstance(item, str):\n                    item_type = builtins.type(item).__name__\n                    raise TypeError(\n                        f\"{self.inipath}: config option '{name}' expects a list of strings, \"\n                        f\"but item at index {i} is {item_type}: {item!r}\"\n                    )\n            return list(value)\n        elif type == \"bool\":\n            # Expect a boolean.\n            if not isinstance(value, bool):\n                raise TypeError(\n                    f\"{self.inipath}: config option '{name}' expects a bool, \"\n                    f\"got {value_type}: {value!r}\"\n                )\n            return value\n        elif type == \"int\":\n            # Expect an integer (but not bool, which is a subclass of int).\n            if not isinstance(value, int) or isinstance(value, bool):\n                raise TypeError(\n                    f\"{self.inipath}: config option '{name}' expects an int, \"\n                    f\"got {value_type}: {value!r}\"\n                )\n            return value\n        elif type == \"float\":\n            # Expect a float or integer only.\n            if not isinstance(value, (float, int)) or isinstance(value, bool):\n                raise TypeError(\n                    f\"{self.inipath}: config option '{name}' expects a float, \"\n                    f\"got {value_type}: {value!r}\"","sourceCodeStart":1978,"sourceCodeEnd":2014,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L1978-L2014","documentation":"Raised by pytest's TOML config parser when a 'bool'-type ini option receives a non-boolean value. TOML mode requires a literal true or false; it does not coerce strings like \"yes\"/\"no\"/\"1\"/\"0\". The error reports the actual type and value.","triggerScenarios":"An addini(type='bool') option is set to a string, integer, or other non-bool in pyproject.toml. Example: addopts_verbose = \"true\" (a string) or addopts_verbose = 1 (an int) instead of addopts_verbose = true (a TOML boolean). The `isinstance(value, bool)` check fails.","commonSituations":"Quoting a boolean (making it a string). Using 0/1 integers instead of true/false. Copying ini-style values where string \"true\" was accepted. Forgetting TOML booleans are unquoted lowercase keywords.","solutions":["Use unquoted TOML booleans: change `addopts_verbose = \"true\"` to `addopts_verbose = true`","Replace 0/1 with false/true respectively","If the value comes from a variable or inline table, ensure the expression evaluates to a TOML bool"],"exampleFix":"// pyproject.toml — before\n[tool.pytest.ini_options]\naddopts_verbose = \"true\"\n\n// after\n[tool.pytest.ini_options]\naddopts_verbose = true","handlingStrategy":"validation","validationCode":"import tomllib\nwith open('pyproject.toml', 'rb') as f:\n    data = tomllib.load(f)\nopts = data.get('tool', {}).get('pytest', {}).get('ini_options', {})\nfor key, val in opts.items():\n    # Heuristic: option names likely to be bool\n    if isinstance(val, str) and val.lower() in ('true', 'false', 'yes', 'no', '1', '0'):\n        print(f\"{key}: looks like an unquoted bool — got string {val!r}, consider {val.lower()}\")","typeGuard":"def is_toml_bool(value: object) -> bool:\n    # In TOML, booleans are native Python bool after parsing\n    return isinstance(value, bool)","tryCatchPattern":null,"preventionTips":["Use unquoted TOML booleans: true / false (lowercase, no quotes)","Never quote boolean values in TOML","Replace 0/1 integers with false/true for bool options"],"tags":["pytest","config","toml","type-validation","bool"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}