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 @@ -123,7 +123,20 @@ def pytest_runtest_call(item: Any) -> Generator[None, Any, None]:
raise _BaseExceptionGroup("Soft assertion failures", errors)


# Fixtures defined by this plugin that (transitively) require a browser and
# therefore "browser_name". When one of them is requested through a user
# override of e.g. the "page" fixture, some pytest versions drop "browser_name"
# from the fixture closure, which would silently disable running the test
# against multiple browsers.
# https://github.com/microsoft/playwright-pytest/issues/172
_BROWSER_FIXTURES = ("page", "context", "new_context", "browser", "browser_type")


def pytest_generate_tests(metafunc: Any) -> None:
if "browser_name" not in metafunc.fixturenames and any(
name in metafunc.fixturenames for name in _BROWSER_FIXTURES
):
metafunc.fixturenames.append("browser_name")
if "browser_name" in metafunc.fixturenames:
browsers = metafunc.config.option.browser or ["chromium"]
metafunc.parametrize("browser_name", browsers, scope="session")
Expand Down
13 changes: 13 additions & 0 deletions pytest-playwright/pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,20 @@ def pytest_runtest_call(item: Any) -> Generator[None, Any, None]:
raise _BaseExceptionGroup("Soft assertion failures", errors)


# Fixtures defined by this plugin that (transitively) require a browser and
# therefore "browser_name". When one of them is requested through a user
# override of e.g. the "page" fixture, some pytest versions drop "browser_name"
# from the fixture closure, which would silently disable running the test
# against multiple browsers.
# https://github.com/microsoft/playwright-pytest/issues/172
_BROWSER_FIXTURES = ("page", "context", "new_context", "browser", "browser_type")


def pytest_generate_tests(metafunc: Any) -> None:
if "browser_name" not in metafunc.fixturenames and any(
name in metafunc.fixturenames for name in _BROWSER_FIXTURES
):
metafunc.fixturenames.append("browser_name")
if "browser_name" in metafunc.fixturenames:
browsers = metafunc.config.option.browser or ["chromium"]
metafunc.parametrize("browser_name", browsers, scope="session")
Expand Down
25 changes: 25 additions & 0 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,31 @@ async def test_multiple_browsers(page):
result.assert_outcomes(passed=3)


def test_multiple_browsers_with_overridden_page_fixture(
testdir: pytest.Testdir,
) -> None:
# Overriding the "page" fixture must not disable running the test against
# each requested browser.
# https://github.com/microsoft/playwright-pytest/issues/172
testdir.makepyfile(
"""
import pytest

@pytest.fixture
def page(page):
yield page

def test_a(page):
pass
"""
)
result = testdir.runpytest(
"--collect-only", "-q", "--browser", "chromium", "--browser", "firefox"
)
assert result.ret == 0
result.stdout.fnmatch_lines(["*test_a*chromium*", "*test_a*firefox*"])


def test_browser_context_args(testdir: pytest.Testdir) -> None:
testdir.makeconftest(
"""
Expand Down
25 changes: 25 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,31 @@ def test_multiple_browsers(page):
result.assert_outcomes(passed=3)


def test_multiple_browsers_with_overridden_page_fixture(
testdir: pytest.Testdir,
) -> None:
# Overriding the "page" fixture must not disable running the test against
# each requested browser.
# https://github.com/microsoft/playwright-pytest/issues/172
testdir.makepyfile(
"""
import pytest

@pytest.fixture
def page(page):
yield page

def test_a(page):
pass
"""
)
result = testdir.runpytest(
"--collect-only", "-q", "--browser", "chromium", "--browser", "firefox"
)
assert result.ret == 0
result.stdout.fnmatch_lines(["*test_a*chromium*", "*test_a*firefox*"])


def test_browser_context_args(testdir: pytest.Testdir) -> None:
testdir.makeconftest(
"""
Expand Down
Loading