{"id":"b906fb7b9c89efd6","repo":"pytest-dev/pytest","slug":"expected-an-int-string-for-option-name-of-type-i","errorCode":null,"errorMessage":"Expected an int string for option {name} of type integer, but got: {value!r}","messagePattern":"Expected an int string for option (.+?) of type integer, but got: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":1931,"sourceCode":"                if self.inipath is not None\n                else self.invocation_params.dir\n            )\n            input_values = shlex.split(value) if isinstance(value, str) else value\n            return [dp / x for x in input_values]\n        elif type == \"args\":\n            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,","sourceCodeStart":1913,"sourceCodeEnd":1949,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L1913-L1949","documentation":"Raised by Config._getini_ini (config/__init__.py:1929-1933) for an option of type 'int' when, in INI mode, the value is not a str. INI files always yield str/list[str], so a non-str here indicates the value arrived from a non-ini source masquerading as ini mode (e.g. a programmatic override injecting an int). int(value) is only attempted on str.","triggerScenarios":"Calling _getini_ini directly with a non-str value for an int-typed option, or a conftest/CLI override that injects an int into _inicfg under ini mode for an int option. Not reachable from a well-formed .ini file read.","commonSituations":"Programmatic test configuration that mutates config._inicfg with native ints; plugin internals bypassing the normal parse path; rare edge cases after partial refactors of the config layer.","solutions":["Ensure int-typed ini values pass through the parser as strings (the normal .ini path) so int(value) can coerce them.","If injecting programmatically, str() the value before placing it into _inicfg, or use getini via the proper API.","Prefer setting int options through CLI flags or pyproject.toml rather than direct dict mutation."],"exampleFix":"# before\nconfig._inicfg['count'] = ConfigValue(value=5, ...)  # int, not str\n\n# after\nconfig._inicfg['count'] = ConfigValue(value='5', ...)","handlingStrategy":"validation","validationCode":"def coerce_int_str(value):\n    if not isinstance(value, str):\n        value = str(value)\n    int(value)  # validate parseable\n    return value","typeGuard":"def is_int_str(value) -> bool:\n    return isinstance(value, str) and value.lstrip('-').isdigit()","tryCatchPattern":"try:\n    config.getini(name)\nexcept (TypeError, ValueError):\n    # normalize injected value to str and reload","preventionTips":["Do not inject native ints into _inicfg directly; pass strings.","Prefer CLI/TOML paths over manual config mutation.","Unit-test plugin config paths with both str and int inputs."],"tags":["config","ini","int-coercion","type-mismatch","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}