Improve error message in presence of conflicting options
What's the problem this feature will solve?
When 2 plugins add/register the command-line option, the error displayed by pytest is not clear enough. It would be nice if pytest could display the list of plugins adding the same option.
Describe the solution you'd like
The actual error is:
pytest --help
Traceback (most recent call last):
File "/home/harmin/.local/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 192, in console_main
code = main()
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 150, in main
config = _prepareconfig(args, plugins)
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 331, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/helpconfig.py", line 104, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/usr/local/lib/python3.8/dist-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1075, in pytest_cmdline_parse
self.parse(args)
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1430, in parse
args = self._parser.parse_setoption(
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 143, in parse_setoption
parsedoption = self.parse(args, namespace=namespace)
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 113, in parse
self.optparser = self._getparser()
File "/home/harmin/.local/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 130, in _getparser
arggroup.add_argument(*n, **a)
File "/usr/lib/python3.8/argparse.py", line 1398, in add_argument
return self._add_action(action)
File "/usr/lib/python3.8/argparse.py", line 1602, in _add_action
action = super(_ArgumentGroup, self)._add_action(action)
File "/usr/lib/python3.8/argparse.py", line 1412, in _add_action
self._check_conflict(action)
File "/usr/lib/python3.8/argparse.py", line 1551, in _check_conflict
conflict_handler(action, confl_optionals)
File "/usr/lib/python3.8/argparse.py", line 1560, in _handle_conflict_error
raise ArgumentError(action, message % conflict_string)
argparse.ArgumentError: argument --browser: conflicting option string: --browser
It would be nice to add or replace the last line with a list of plugins adding the same option.
argparse.ArgumentError: argument --browser: conflicting option string: --browser added by plugins: ['plugin1', 'plugin2']
or at least, a more clear, generic message like:
argparse.ArgumentError: argument --browser: conflicting option string: --browser added by two or more plugins.
As time passes by, the number of third-party plugins is going to grow and the risk of command-line option collisions will become inevitable, making the co-existence of some plugins impossible.
A more clear message can help understand the user which plugins are incompatible, so the user can install them in separate python virtual environments.
Alternative Solutions
No workaround.
Additional context
A more clear message can help understand the user which plugins are incompatible, so the user can install them in separate python virtual environments.
This seems like a pain, is there no way the plugin could be included in the cmd argument? So pytest <plugin> [command] rather than pytest <command>? That would add some form of name spacing and prevent the issue.