{"record":{"id":"1c42c1aa25eb8c9e","repo":"pytest-dev/pytest","slug":"self-inipath-config-option-name-expects-a-s-1c42c1","errorCode":null,"errorMessage":"{self.inipath}: config option '{name}' expects a string, got {value_type}: {value!r}","messagePattern":"(.+?): config option '(.+?)' expects a string, got (.+?): (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":2020,"sourceCode":"            # 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}\"\n                )\n            return value\n        elif type == \"string\":\n            # Expect a string.\n            if not isinstance(value, str):\n                raise TypeError(\n                    f\"{self.inipath}: config option '{name}' expects a string, \"\n                    f\"got {value_type}: {value!r}\"\n                )\n            return value\n        else:\n            return self._getini_unknown_type(name, type, value)\n\n    def _getconftest_pathlist(\n        self, name: str, path: pathlib.Path\n    ) -> list[pathlib.Path] | None:\n        try:\n            mod, relroots = self.pluginmanager._rget_with_confmod(name, path)\n        except KeyError:\n            return None\n        assert mod.__file__ is not None\n        modpath = pathlib.Path(mod.__file__).parent\n        values: list[pathlib.Path] = []\n        for relroot in relroots:","sourceCodeStart":2002,"sourceCodeEnd":2038,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L2002-L2038","documentation":"Raised by pytest's TOML config parser when a 'string'-type ini option receives a non-string value. TOML mode requires the value to be a str; numbers, bools, dates, arrays, and tables are all rejected without coercion.","triggerScenarios":"An addini(type='string') option (the default type when type=None) is set to a non-string in pyproject.toml. Example: python_files = 42 or minversion = 8.0 instead of minversion = \"8.0\". The `isinstance(value, str)` check fails.","commonSituations":"Omitting quotes around a value that looks like a number or version string. Using a TOML array for a single-string option. Providing a TOML date or datetime where a string is expected.","solutions":["Quote the value: change `minversion = 8.0` to `minversion = \"8.0\"`","If multiple values are needed, check whether the option supports a list type; if not, keep a single string","Validate the parsed value is str using tomllib"],"exampleFix":"// pyproject.toml — before\n[tool.pytest.ini_options]\nminversion = 8.0\n\n// after\n[tool.pytest.ini_options]\nminversion = \"8.0\"","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    if not isinstance(val, str) and not isinstance(val, list) and not isinstance(val, bool):\n        print(f\"{key}: got {type(val).__name__} {val!r}, string type expects a quoted string\")","typeGuard":"def is_toml_string(value: object) -> bool:\n    return isinstance(value, str)","tryCatchPattern":null,"preventionTips":["Quote all string values in TOML, including version numbers and patterns","Do not use arrays or tables for single-value string options","Validate config values are str with tomllib after editing"],"tags":["pytest","config","toml","type-validation","string"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}