{"id":"cb2703f7872a85c2","repo":"pytest-dev/pytest","slug":"unknown-configuration-value-name-r","errorCode":null,"errorMessage":"unknown configuration value: {name!r}","messagePattern":"unknown configuration value: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":1806,"sourceCode":"        self._inicache[canonical_name] = val = self._getini(canonical_name)\n        return val\n\n    # Meant for easy monkeypatching by legacypath plugin.\n    # Can be inlined back (with no cover removed) once legacypath is gone.\n    def _getini_unknown_type(self, name: str, type: str, value: object):\n        msg = (\n            f\"Option {name} has unknown configuration type {type} with value {value!r}\"\n        )\n        raise ValueError(msg)  # pragma: no cover\n\n    def _getini(self, name: str):\n        # If this is an alias, resolve to canonical name.\n        canonical_name = self._parser._ini_aliases.get(name, name)\n\n        try:\n            _description, type, default = self._parser._inidict[canonical_name]\n        except KeyError as e:\n            raise ValueError(f\"unknown configuration value: {name!r}\") from e\n\n        # Collect all possible values (canonical name + aliases) from _inicfg.\n        # Each candidate is (ConfigValue, is_canonical).\n        candidates = []\n        if canonical_name in self._inicfg:\n            candidates.append((self._inicfg[canonical_name], True))\n        for alias, target in self._parser._ini_aliases.items():\n            if target == canonical_name and alias in self._inicfg:\n                candidates.append((self._inicfg[alias], False))\n\n        if not candidates:\n            return default\n\n        # Pick the best candidate based on precedence:\n        # 1. CLI override takes precedence over file, then\n        # 2. Canonical name takes precedence over alias.\n        selected = max(candidates, key=lambda x: (x[0].origin == \"override\", x[1]))[0]\n        value = selected.value","sourceCodeStart":1788,"sourceCodeEnd":1824,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/config/__init__.py#L1788-L1824","documentation":"Raised by Config._getini (config/__init__.py:1799-1806) when getini(name) is called for an option that was never registered via parser.addini during pytest_addoption. The lookup against _parser._inidict raises KeyError, which is converted to a ValueError naming the offending option.","triggerScenarios":"Calling config.getini('my_opt') in a conftest or plugin when no plugin has invoked parser.addini('my_opt', ...) in its pytest_addoption hook; using a misspelled or removed ini key; referencing an option from a plugin that is not installed.","commonSituations":"Typo in the ini key passed to getini; referencing a plugin-provided ini option without enabling the plugin; version upgrade where an ini option was renamed/removed (e.g. legacy options after a pytest major bump).","solutions":["Register the option first: in a conftest.py pytest_addoption hook call parser.addini(name, help, type, default).","Check the spelling/casing of the name against the addini registration and the getini call.","If the option comes from a plugin, ensure the plugin is installed and loaded (pip show / pytest --trace-config).","On version upgrades, consult the changelog for renamed/removed ini options."],"exampleFix":"# before (conftest.py)\ndef pytest_configure(config):\n    val = config.getini('my_flag')  # never registered\n\n# after\ndef pytest_addoption(parser):\n    parser.addini('my_flag', help='toggle', type='bool', default=False)","handlingStrategy":"validation","validationCode":"def safe_getini(config, name, default=None):\n    if name not in config._parser._inidict:\n        return default\n    return config.getini(name)","typeGuard":"def ini_is_registered(config, name: str) -> bool:\n    return name in config._parser._inidict","tryCatchPattern":"try:\n    val = config.getini(name)\nexcept ValueError:\n    val = None  # option not registered","preventionTips":["Register ini options in pytest_addoption before reading them.","Verify the plugin providing an option is installed (pytest --trace-config).","Keep a single conftest declaring all custom ini keys."],"tags":["config","ini","getini","pytest"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}