Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions pytest-playwright/pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading