diff --git a/tests/async/conftest.py b/tests/async/conftest.py index 1048be55c..a96fd3ec5 100644 --- a/tests/async/conftest.py +++ b/tests/async/conftest.py @@ -57,6 +57,10 @@ async def launch(**kwargs): yield launch for browser in browsers: + if browser.contexts: + raise Exception( + "Test failed to close a context it created via browser_factory fixture. Explicitly close context, or use context_factory." + ) await browser.close() @@ -64,6 +68,10 @@ async def launch(**kwargs): async def browser(browser_factory): browser = await browser_factory() yield browser + if browser.contexts: + raise Exception( + "Test failed to close a context it created via browser fixture. Explicitly close context, or use context_factory." + ) await browser.close() diff --git a/tests/async/test_har.py b/tests/async/test_har.py index cd1c871a6..fb820232d 100644 --- a/tests/async/test_har.py +++ b/tests/async/test_har.py @@ -503,6 +503,7 @@ async def test_should_round_trip_har_zip( await expect(page_2.locator("body")).to_have_css( "background-color", "rgb(255, 192, 203)" ) + await context_2.close() async def test_should_round_trip_har_with_post_data( @@ -536,6 +537,7 @@ async def test_should_round_trip_har_with_post_data( assert await page_2.evaluate(fetch_function, "3") == "3" with pytest.raises(Exception): await page_2.evaluate(fetch_function, "4") + await context_2.close() async def test_should_disambiguate_by_header( @@ -578,6 +580,7 @@ async def test_should_disambiguate_by_header( assert await page_2.evaluate(fetch_function, "baz2") == "baz2" assert await page_2.evaluate(fetch_function, "baz3") == "baz3" assert await page_2.evaluate(fetch_function, "baz4") == "baz1" + await context_2.close() async def test_should_produce_extracted_zip( @@ -605,6 +608,7 @@ async def test_should_produce_extracted_zip( await expect(page_2.locator("body")).to_have_css( "background-color", "rgb(255, 192, 203)" ) + await context_2.close() async def test_should_update_har_zip_for_context( @@ -627,6 +631,7 @@ async def test_should_update_har_zip_for_context( await expect(page_2.locator("body")).to_have_css( "background-color", "rgb(255, 192, 203)" ) + await context_2.close() async def test_should_update_har_zip_for_page( @@ -649,6 +654,7 @@ async def test_should_update_har_zip_for_page( await expect(page_2.locator("body")).to_have_css( "background-color", "rgb(255, 192, 203)" ) + await context_2.close() async def test_should_update_extracted_har_zip_for_page( @@ -675,3 +681,4 @@ async def test_should_update_extracted_har_zip_for_page( await expect(page_2.locator("body")).to_have_css( "background-color", "rgb(255, 192, 203)" ) + await context_2.close() diff --git a/tests/sync/conftest.py b/tests/sync/conftest.py index d7942bf90..ad2f4e297 100644 --- a/tests/sync/conftest.py +++ b/tests/sync/conftest.py @@ -63,6 +63,10 @@ def browser( ) -> Generator[Browser, None, None]: browser = browser_type.launch(**launch_arguments) yield browser + if browser.contexts: + raise Exception( + "Test failed to close a context it created via browser fixture. Explicitly close context, or use context fixture" + ) browser.close() diff --git a/tests/sync/test_har.py b/tests/sync/test_har.py index 81452c9de..c5b20ed56 100644 --- a/tests/sync/test_har.py +++ b/tests/sync/test_har.py @@ -438,6 +438,7 @@ def test_should_round_trip_har_zip( page_2.goto(server.PREFIX + "/one-style.html") assert "hello, world!" in page_2.content() expect(page_2.locator("body")).to_have_css("background-color", "rgb(255, 192, 203)") + context_2.close() def test_should_round_trip_har_with_post_data( @@ -471,6 +472,7 @@ def test_should_round_trip_har_with_post_data( assert page_2.evaluate(fetch_function, "3") == "3" with pytest.raises(Exception): page_2.evaluate(fetch_function, "4") + context_2.close() def test_should_disambiguate_by_header( @@ -512,6 +514,7 @@ def test_should_disambiguate_by_header( assert page_2.evaluate(fetch_function, "baz2") == "baz2" assert page_2.evaluate(fetch_function, "baz3") == "baz3" assert page_2.evaluate(fetch_function, "baz4") == "baz1" + context_2.close() def test_should_produce_extracted_zip( @@ -537,6 +540,7 @@ def test_should_produce_extracted_zip( page_2.goto(server.PREFIX + "/one-style.html") assert "hello, world!" in page_2.content() expect(page_2.locator("body")).to_have_css("background-color", "rgb(255, 192, 203)") + context_2.close() def test_should_update_har_zip_for_context( @@ -557,6 +561,7 @@ def test_should_update_har_zip_for_context( page_2.goto(server.PREFIX + "/one-style.html") assert "hello, world!" in page_2.content() expect(page_2.locator("body")).to_have_css("background-color", "rgb(255, 192, 203)") + context_2.close() def test_should_update_har_zip_for_page( @@ -577,6 +582,7 @@ def test_should_update_har_zip_for_page( page_2.goto(server.PREFIX + "/one-style.html") assert "hello, world!" in page_2.content() expect(page_2.locator("body")).to_have_css("background-color", "rgb(255, 192, 203)") + context_2.close() def test_should_update_extracted_har_zip_for_page( @@ -601,3 +607,4 @@ def test_should_update_extracted_har_zip_for_page( page_2.goto(server.PREFIX + "/one-style.html") assert "hello, world!" in page_2.content() expect(page_2.locator("body")).to_have_css("background-color", "rgb(255, 192, 203)") + context_2.close()