diff --git a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py index 9c165c7..2917e04 100644 --- a/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py +++ b/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py @@ -413,14 +413,24 @@ def device(pytestconfig: Any) -> Optional[str]: return pytestconfig.getoption("--device") +PW_SYNC_CANONICAL_NAME = "pytest_playwright.pytest_playwright" +PLUGIN_INCOMPATIBLE_MESSAGE = "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them." + + def pytest_addoption( parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager ) -> None: - # Check for incompatible sync plugin early - if pluginmanager.has_plugin("pytest_playwright.pytest_playwright"): - raise RuntimeError( - "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them." - ) + # Check for incompatible sync plugin with canonical name + if pluginmanager.has_plugin(PW_SYNC_CANONICAL_NAME): + raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE) + # Check for incompatible sync plugin with common name + common_name_plugin = pluginmanager.get_plugin("playwright") + if ( + common_name_plugin is not None + and pluginmanager.get_canonical_name(common_name_plugin) + == PW_SYNC_CANONICAL_NAME + ): + raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE) group = parser.getgroup("playwright", "Playwright") group.addoption( "--browser", diff --git a/pytest-playwright/pytest_playwright/pytest_playwright.py b/pytest-playwright/pytest_playwright/pytest_playwright.py index ec362fa..d418395 100644 --- a/pytest-playwright/pytest_playwright/pytest_playwright.py +++ b/pytest-playwright/pytest_playwright/pytest_playwright.py @@ -408,14 +408,26 @@ def device(pytestconfig: Any) -> Optional[str]: return pytestconfig.getoption("--device") +PW_ASYNC_CANONICAL_NAME = "pytest_playwright_asyncio.pytest_playwright" +PLUGIN_INCOMPATIBLE_MESSAGE = "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them." + + def pytest_addoption( parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager ) -> None: - # Check for incompatible async plugin early - if pluginmanager.has_plugin("pytest_playwright_asyncio.pytest_playwright"): + # Check for incompatible async plugin with canonical name + if pluginmanager.has_plugin(PW_ASYNC_CANONICAL_NAME): raise RuntimeError( "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them." ) + # Check for incompatible async plugin with common name + common_name_plugin = pluginmanager.get_plugin("playwright-asyncio") + if ( + common_name_plugin is not None + and pluginmanager.get_canonical_name(common_name_plugin) + == PW_ASYNC_CANONICAL_NAME + ): + raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE) group = parser.getgroup("playwright", "Playwright") group.addoption( "--browser",