Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ dmypy.json

.DS_Store
/test-results/

# Claude Code local configuration files
.claude/
CLAUDE.local.md
DEVELOPER.local.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ async def launch(**kwargs: Dict) -> Browser:

@pytest_asyncio.fixture(scope="session")
async def browser(
launch_browser: Callable[[], Awaitable[Browser]]
launch_browser: Callable[[], Awaitable[Browser]],
) -> AsyncGenerator[Browser, None]:
browser = await launch_browser()
yield browser
Expand Down Expand Up @@ -413,7 +413,14 @@ def device(pytestconfig: Any) -> Optional[str]:
return pytestconfig.getoption("--device")


def pytest_addoption(parser: Any) -> None:
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."
)
group = parser.getgroup("playwright", "Playwright")
group.addoption(
"--browser",
Expand Down
9 changes: 8 additions & 1 deletion pytest-playwright/pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,14 @@ def device(pytestconfig: Any) -> Optional[str]:
return pytestconfig.getoption("--device")


def pytest_addoption(parser: Any) -> None:
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"):
raise RuntimeError(
"pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
)
group = parser.getgroup("playwright", "Playwright")
group.addoption(
"--browser",
Expand Down
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
import sys
import os
import socket
from typing import Generator, Optional, Type
from typing import Any, Generator, Optional, Type
import pytest
import threading
import http.server
import socketserver

pytest_plugins = ["pytester"]


def pytest_configure(config: Any) -> None:
config.addinivalue_line("markers", "no_add_ini: mark test to skip adding ini file")


# The testdir fixture which we use to perform unit tests will set the home directory
# To a temporary directory of the created test. This would result that the browsers will
# be re-downloaded each time. By setting the pw browser path directory we can prevent that.
Expand Down
42 changes: 40 additions & 2 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def pytester(pytester: pytest.Pytester) -> pytest.Pytester:


@pytest.fixture(autouse=True)
def _add_async_marker(testdir: pytest.Testdir) -> None:
def _add_ini_asyncio(request: pytest.FixtureRequest, testdir: pytest.Testdir) -> None:
if "no_add_ini" in request.keywords:
return
testdir.makefile(
".ini",
pytest="""
Expand All @@ -44,6 +46,42 @@ def _add_async_marker(testdir: pytest.Testdir) -> None:
)


@pytest.mark.no_add_ini
def test_sync_async_incompatibility(testdir: pytest.Testdir) -> None:
# This test needs to load both playwright and playwright-asyncio plugins
# to trigger the incompatibility check
testdir.makefile(
".ini",
pytest="""
[pytest]
addopts = --maxfail=1
asyncio_default_test_loop_scope = session
asyncio_default_fixture_loop_scope = session
""",
)
testdir.makepyfile(
"""
import pytest
@pytest.mark.asyncio
async def test_foo():
pass
"""
)
# Explicitly load both plugins to trigger the incompatibility
result = testdir.runpytest(
"-p",
"pytest_playwright.pytest_playwright",
"-p",
"pytest_playwright_asyncio.pytest_playwright",
)
assert result.ret != 0
output = "\n".join(result.outlines + result.errlines)
assert (
"pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
in output
)


def test_default(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""
Expand Down Expand Up @@ -237,7 +275,7 @@ async def test_is_firefox(page, browser_name, is_chromium, is_firefox, is_webkit
assert is_chromium is False
assert is_firefox
assert is_webkit is False
"""
"""
)
result = testdir.runpytest("--browser", "firefox")
result.assert_outcomes(passed=1)
Expand Down
38 changes: 37 additions & 1 deletion tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def pytester(pytester: pytest.Pytester) -> pytest.Pytester:


@pytest.fixture(autouse=True)
def _add_ini(testdir: pytest.Testdir) -> None:
def _add_ini(request: pytest.FixtureRequest, testdir: pytest.Testdir) -> None:
if "no_add_ini" in request.keywords:
return
testdir.makefile(
".ini",
pytest="""
Expand All @@ -43,6 +45,40 @@ def _add_ini(testdir: pytest.Testdir) -> None:
)


@pytest.mark.no_add_ini
def test_sync_async_incompatibility(testdir: pytest.Testdir) -> None:
# This test needs to load both playwright and playwright-asyncio plugins
# to trigger the incompatibility check
testdir.makefile(
".ini",
pytest="""
[pytest]
addopts = --maxfail=1
""",
)
testdir.makepyfile(
"""
import pytest

def test_foo():
pass
"""
)
# Explicitly load both plugins to trigger the incompatibility
result = testdir.runpytest(
"-p",
"pytest_playwright.pytest_playwright",
"-p",
"pytest_playwright_asyncio.pytest_playwright",
)
assert result.ret != 0
output = "\n".join(result.outlines + result.errlines)
assert (
"pytest-playwright and pytest-playwright-asyncio are not compatible. Please use only one of them."
in output
)


def test_default(testdir: pytest.Testdir) -> None:
testdir.makepyfile(
"""
Expand Down
Loading