Skip to content

Commit

Permalink
fix: mark.browser_context_args should clear for the next test (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Oct 9, 2023
1 parent a24c3f8 commit f00a018
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def context(
) -> Generator[BrowserContext, None, None]:
pages: List[Page] = []

browser_context_args = browser_context_args.copy()
context_args_marker = next(request.node.iter_markers("browser_context_args"), None)
additional_context_args = context_args_marker.kwargs if context_args_marker else {}
browser_context_args.update(additional_context_args)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ def test_browser_context_args(page):
result.assert_outcomes(passed=1)


def test_user_defined_browser_context_args_clear_again(testdir: pytest.Testdir) -> None:
testdir.makeconftest(
"""
import pytest
@pytest.fixture(scope="session")
def browser_context_args():
return {"user_agent": "foobar"}
"""
)
testdir.makepyfile(
"""
import pytest
@pytest.mark.browser_context_args(user_agent="overwritten")
def test_browser_context_args(page):
assert page.evaluate("window.navigator.userAgent") == "overwritten"
def test_browser_context_args2(page):
assert page.evaluate("window.navigator.userAgent") == "foobar"
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=2)


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

0 comments on commit f00a018

Please sign in to comment.