Skip to content

Commit

Permalink
fix: don't paramaterize test functions that don't use browser fixtures (
Browse files Browse the repository at this point in the history
  • Loading branch information
jcushman authored Nov 23, 2020
1 parent 858a9b4 commit c461074
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,31 @@ def pytest_configure(config: Any) -> None:
)


def _get_skiplist(request: Any, values: List[str], value_name: str) -> List[str]:
def _get_skiplist(item: Any, values: List[str], value_name: str) -> List[str]:
skipped_values: List[str] = []
# Allowlist
only_marker = request.node.get_closest_marker(f"only_{value_name}")
only_marker = item.get_closest_marker(f"only_{value_name}")
if only_marker:
skipped_values = values
skipped_values.remove(only_marker.args[0])

# Denylist
skip_marker = request.node.get_closest_marker(f"skip_{value_name}")
skip_marker = item.get_closest_marker(f"skip_{value_name}")
if skip_marker:
skipped_values.append(skip_marker.args[0])

return skipped_values


@pytest.fixture(autouse=True)
def skip_browsers(request: Any, browser_name: str) -> None:
def pytest_runtest_setup(item: Any) -> None:
if not hasattr(item, "callspec"):
return
browser_name = item.callspec.params.get("browser_name")
if not browser_name:
return

skip_browsers_names = _get_skiplist(
request, ["chromium", "firefox", "webkit"], "browser"
item, ["chromium", "firefox", "webkit"], "browser"
)

if browser_name in skip_browsers_names:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,29 @@ def test_base_url(page, browser_name):
result.assert_outcomes(passed=1, skipped=2)


def test_parameterization(testdir: Any) -> None:
testdir.makepyfile(
"""
def test_all_browsers(page):
pass
def test_without_browser():
pass
"""
)
result = testdir.runpytest(
"--verbose",
"--browser",
"chromium",
"--browser",
"firefox",
"--browser",
"webkit",
)
result.assert_outcomes(passed=4)
assert "test_without_browser PASSED" in "\n".join(result.outlines)


def test_headful(testdir: Any) -> None:
testdir.makepyfile(
"""
Expand Down

0 comments on commit c461074

Please sign in to comment.