playwright-pytest icon indicating copy to clipboard operation
playwright-pytest copied to clipboard

[BUG]: pytest-playwright-asyncio introduces a duplicate option name

Open nfelt14 opened this issue 6 months ago • 3 comments

When trying to use [pytest-playwright-asyncio](https://pypi.org/project/pytest-playwright-asyncio/), a ValueError is raised due to a duplicate option name:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\...\.venv\Lib\site-packages\pytest\__main__.py", line 9, in <module>
    raise SystemExit(pytest.console_main())
                     ^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 201, in console_main
    code = main()
           ^^^^^^
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 156, in main
    config = _prepareconfig(args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 342, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_hooks.py", line 512, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    raise exception
  File "C:\...\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "C:\...\.venv\Lib\site-packages\_pytest\helpconfig.py", line 112, in pytest_cmdline_parse
    config = yield
             ^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1146, in pytest_cmdline_parse
    self.parse(args)
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1527, in parse
    self._preparse(args, addopts=addopts)
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1412, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "C:\...\.venv\Lib\site-packages\pluggy\_manager.py", line 417, in load_setuptools_entrypoints
    self.register(plugin, name=ep.name)
  File "C:\...\.venv\Lib\site-packages\_pytest\config\__init__.py", line 503, in register
    plugin_name = super().register(plugin, name)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_manager.py", line 169, in register
    hook._maybe_apply_history(hookimpl)
  File "C:\...\.venv\Lib\site-packages\pluggy\_hooks.py", line 580, in _maybe_apply_history
    res = self._hookexec(self.name, [method], kwargs, False)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\.venv\Lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    raise exception
  File "C:\...\.venv\Lib\site-packages\pluggy\_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\...\.venv\Lib\site-packages\pytest_playwright_asyncio\pytest_playwright.py", line 425, in pytest_addoption
    group.addoption(
  File "C:\...\.venv\Lib\site-packages\_pytest\config\argparsing.py", line 405, in addoption
    raise ValueError(f"option names {conflict} already added")
ValueError: option names {'--browser'} already added

nfelt14 avatar Sep 12 '25 16:09 nfelt14

It looks like #294 might fix the issue

nfelt14 avatar Sep 12 '25 16:09 nfelt14

I was able to get the issue to go away by completely uninstalling pytest-playwright.

nfelt14 avatar Sep 12 '25 16:09 nfelt14

There's existing logic to raise an error explaining that users should only install the sync api or the async one, not both -- but the logic doesn't seem to trigger reliably, and unfortunately the error we get later down the track about duplicates is not too helpful.

This is what #294 fixes -- to make said error appear reliably, which should save the users a lot of time.

JamesYFC avatar Oct 01 '25 13:10 JamesYFC