Skip to content

Commit a61b1fd

Browse files
JamesYFCJamesYFC
authored andcommitted
fix: check common name for incompatible plugin
1 parent c1af305 commit a61b1fd

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,24 @@ def device(pytestconfig: Any) -> Optional[str]:
413413
return pytestconfig.getoption("--device")
414414

415415

416+
PW_SYNC_CANONICAL_NAME = "pytest_playwright.pytest_playwright"
417+
PLUGIN_INCOMPATIBLE_MESSAGE = "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
418+
419+
416420
def pytest_addoption(
417421
parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager
418422
) -> None:
419-
# Check for incompatible sync plugin early
420-
if pluginmanager.has_plugin("pytest_playwright.pytest_playwright"):
421-
raise RuntimeError(
422-
"pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
423-
)
423+
# Check for incompatible sync plugin with canonical name
424+
if pluginmanager.has_plugin(PW_SYNC_CANONICAL_NAME):
425+
raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE)
426+
# Check for incompatible sync plugin with common name
427+
common_name_plugin = pluginmanager.get_plugin("playwright")
428+
if (
429+
common_name_plugin is not None
430+
and pluginmanager.get_canonical_name(common_name_plugin)
431+
== PW_SYNC_CANONICAL_NAME
432+
):
433+
raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE)
424434
group = parser.getgroup("playwright", "Playwright")
425435
group.addoption(
426436
"--browser",

pytest-playwright/pytest_playwright/pytest_playwright.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,26 @@ def device(pytestconfig: Any) -> Optional[str]:
408408
return pytestconfig.getoption("--device")
409409

410410

411+
PW_ASYNC_CANONICAL_NAME = "pytest_playwright_asyncio.pytest_playwright"
412+
PLUGIN_INCOMPATIBLE_MESSAGE = "pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
413+
414+
411415
def pytest_addoption(
412416
parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager
413417
) -> None:
414-
# Check for incompatible async plugin early
415-
if pluginmanager.has_plugin("pytest_playwright_asyncio.pytest_playwright"):
418+
# Check for incompatible async plugin with canonical name
419+
if pluginmanager.has_plugin(PW_ASYNC_CANONICAL_NAME):
416420
raise RuntimeError(
417421
"pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
418422
)
423+
# Check for incompatible async plugin with common name
424+
common_name_plugin = pluginmanager.get_plugin("playwright-asyncio")
425+
if (
426+
common_name_plugin is not None
427+
and pluginmanager.get_canonical_name(common_name_plugin)
428+
== PW_ASYNC_CANONICAL_NAME
429+
):
430+
raise RuntimeError(PLUGIN_INCOMPATIBLE_MESSAGE)
419431
group = parser.getgroup("playwright", "Playwright")
420432
group.addoption(
421433
"--browser",

0 commit comments

Comments
 (0)