{"record":{"id":"dc72fa8f91e88a1c","repo":"pytest-dev/pytest","slug":"option-names-conflict-already-added","errorCode":null,"errorMessage":"option names {conflict} already added","messagePattern":"option names (.+?) already added","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/argparsing.py","lineNumber":457,"sourceCode":"        \"\"\"Add an option to this group.\n\n        If a shortened version of a long option is specified, it will\n        be suppressed in the help. ``addoption('--twowords', '--two-words')``\n        results in help showing ``--two-words`` only, but ``--twowords`` gets\n        accepted **and** the automatic destination is in ``args.twowords``.\n\n        :param opts:\n            Option names, can be short or long options.\n            Note that lower-case short options (e.g. `-x`) are reserved.\n        :param attrs:\n            Same attributes as the argparse library's :meth:`add_argument()\n            <argparse.ArgumentParser.add_argument>` function accepts.\n        \"\"\"\n        conflict = set(opts).intersection(\n            name for opt in self.options for name in opt.names()\n        )\n        if conflict:\n            raise ValueError(f\"option names {conflict} already added\")\n\n        if self.parser and \"dest\" not in attrs:\n            dest = _get_argparse_dest(opts)\n            for group in self.parser._groups:\n                for option in group.options:\n                    if option.dest == dest:\n                        raise ValueError(\n                            f\"option dest {dest!r} already used by \"\n                            f\"{option.names()!r} (this is the option that maps to \"\n                            f\"dest {dest!r}); pass dest={dest!r} explicitly \"\n                            \"to share the destination\"\n                        )\n        self._addoption_inner(opts, attrs, allow_reserved=False)\n\n    def _addoption(self, *opts: str, **attrs: Any) -> None:\n        \"\"\"Like addoption(), but also allows registering short lower case options (e.g. -x),\n        which are reserved for pytest core.\"\"\"\n        self._addoption_inner(opts, attrs, allow_reserved=True)","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/argparsing.py#L439-L475","documentation":"Raised by OptionGroup.addoption() when one or more option names (e.g., '--flag', '-f') in the current call conflict with names already added to the same option group. The conflict set is computed by intersecting new opts with all names of existing options in the group.","triggerScenarios":"Calling group.addoption('--verbose') when '--verbose' was already added to the same group in a prior addoption call. The set intersection between new opts and existing option names is non-empty.","commonSituations":"Two plugins registering the same CLI flag. A conftest.py re-registering an option already added by a plugin. Copy-pasting addoption calls. Version upgrade where a plugin now registers a flag your conftest also defines.","solutions":["Rename the conflicting option in your addoption call to avoid the collision","Guard the addoption call with a check for whether the option already exists","If a plugin provides the option, remove the duplicate registration from your conftest.py","Move the option to a different group if appropriate"],"exampleFix":"# before\ngroup.addoption('--verbose', action='store_true')\n# ... elsewhere in same group\ngroup.addoption('--verbose', action='store_true')\n\n# after\ngroup.addoption('--verbose', action='store_true')\n# remove or rename the second call","handlingStrategy":"validation","validationCode":"def check_no_option_conflict(group, opts: list[str]) -> set[str]:\n    existing = {name for opt in group.options for name in opt.names()}\n    return set(opts).intersection(existing)\n# Usage: conflicts = check_no_option_conflict(group, ['--verbose'])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard addoption calls: check group.options for existing names before adding","Namespace custom CLI flags with a plugin prefix to avoid collisions: --mypkg-flag","If a plugin provides an option, do not re-register it in conftest.py"],"tags":["pytest","config","addoption","naming-conflict","plugin-api","cli"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}