{"record":{"id":"dfef492135b9894f","repo":"pytest-dev/pytest","slug":"no-option-named-name-r","errorCode":null,"errorMessage":"no option named {name!r}","messagePattern":"no option named (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":2070,"sourceCode":"        :param default: Fallback value if no option of that name is **declared** via :hook:`pytest_addoption`.\n            Note this parameter will be ignored when the option is **declared** even if the option's value is ``None``.\n        :param skip: If ``True``, raise :func:`pytest.skip` if option is undeclared or has a ``None`` value.\n            Note that even if ``True``, if a default was specified it will be returned instead of a skip.\n        \"\"\"\n        name = self._parser._opt2dest.get(name, name)\n        try:\n            val = getattr(self.option, name)\n            if val is None and skip:\n                raise AttributeError(name)\n            return val\n        except AttributeError as e:\n            if default is not NOTSET:\n                return default\n            if skip:\n                import pytest\n\n                pytest.skip(f\"no {name!r} option found\")\n            raise ValueError(f\"no option named {name!r}\") from e\n\n    def getvalue(self, name: str, path=None):\n        \"\"\"Deprecated, use getoption() instead.\"\"\"\n        return self.getoption(name)\n\n    def getvalueorskip(self, name: str, path=None):\n        \"\"\"Deprecated, use getoption(skip=True) instead.\"\"\"\n        return self.getoption(name, skip=True)\n\n    #: Verbosity type for failed assertions (see :confval:`verbosity_assertions`).\n    VERBOSITY_ASSERTIONS: Final = \"assertions\"\n    #: Verbosity type for test case execution (see :confval:`verbosity_test_cases`).\n    VERBOSITY_TEST_CASES: Final = \"test_cases\"\n    #: Verbosity type for failed subtests (see :confval:`verbosity_subtests`).\n    VERBOSITY_SUBTESTS: Final = \"subtests\"\n\n    _VERBOSITY_INI_DEFAULT: Final = \"auto\"\n","sourceCodeStart":2052,"sourceCodeEnd":2088,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L2052-L2088","documentation":"Raised by Config.getoption() when the requested option name is neither declared via pytest_addoption nor present on the config's option namespace, and no default was supplied. This is a user-facing API: plugins and conftest.py code call config.getoption('name') to retrieve CLI/ini values. The error is only raised when default is NOTSET and skip is False.","triggerScenarios":"Calling config.getoption('some_flag') in a fixture, hook, or plugin where 'some_flag' was never registered with parser.addoption('--some-flag') in a pytest_addoption hook. The lookup getattr(self.option, name) raises AttributeError, default is NOTSET, and skip is False.","commonSituations":"Typo in the option name string. Referencing an option provided by a plugin that is not installed. Calling getoption before pytest_addoption has run. Forgetting to register the option in conftest.py.","solutions":["Check the option name matches the addoption dest (e.g., --my-flag has dest my_flag)","Pass a default: config.getoption('name', default=False) to avoid the error for optional flags","Use skip=True if the option being absent should skip the test rather than error: config.getoption('name', skip=True)","Ensure the plugin that registers the option via pytest_addoption is installed and loaded"],"exampleFix":"# before\nval = config.getoption('my_flag')\n\n# after\nval = config.getoption('my_flag', default=False)","handlingStrategy":"try-catch","validationCode":"# Check option is declared before calling getoption\ndeclared = name in dir(config.option) if hasattr(config, 'option') else False\nif not declared:\n    print(f\"Option {name!r} is not declared; consider adding a default or skip=True\")","typeGuard":null,"tryCatchPattern":"try:\n    val = config.getoption('my_flag', default=False)\nexcept ValueError:\n    # Option not declared — handle gracefully\n    val = False","preventionTips":["Always pass a default= to getoption for optional flags","Use skip=True when the option's absence should skip the test instead of erroring","Register all options via pytest_addoption in conftest.py before referencing them","Double-check option dest names: --my-flag becomes my_flag"],"tags":["pytest","config","getoption","plugin-api","option-lookup"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}