Skip to content

Commit f00a018

Browse files
authored
fix: mark.browser_context_args should clear for the next test (#189)
1 parent a24c3f8 commit f00a018

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pytest_playwright/pytest_playwright.py

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def context(
232232
) -> Generator[BrowserContext, None, None]:
233233
pages: List[Page] = []
234234

235+
browser_context_args = browser_context_args.copy()
235236
context_args_marker = next(request.node.iter_markers("browser_context_args"), None)
236237
additional_context_args = context_args_marker.kwargs if context_args_marker else {}
237238
browser_context_args.update(additional_context_args)

tests/test_playwright.py

+26
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,32 @@ def test_browser_context_args(page):
194194
result.assert_outcomes(passed=1)
195195

196196

197+
def test_user_defined_browser_context_args_clear_again(testdir: pytest.Testdir) -> None:
198+
testdir.makeconftest(
199+
"""
200+
import pytest
201+
202+
@pytest.fixture(scope="session")
203+
def browser_context_args():
204+
return {"user_agent": "foobar"}
205+
"""
206+
)
207+
testdir.makepyfile(
208+
"""
209+
import pytest
210+
211+
@pytest.mark.browser_context_args(user_agent="overwritten")
212+
def test_browser_context_args(page):
213+
assert page.evaluate("window.navigator.userAgent") == "overwritten"
214+
215+
def test_browser_context_args2(page):
216+
assert page.evaluate("window.navigator.userAgent") == "foobar"
217+
"""
218+
)
219+
result = testdir.runpytest()
220+
result.assert_outcomes(passed=2)
221+
222+
197223
def test_chromium(testdir: pytest.Testdir) -> None:
198224
testdir.makepyfile(
199225
"""

0 commit comments

Comments
 (0)