diff --git a/solara/test/pytest_plugin.py b/solara/test/pytest_plugin.py index 8a0709251..e23b7f580 100644 --- a/solara/test/pytest_plugin.py +++ b/solara/test/pytest_plugin.py @@ -169,6 +169,15 @@ def SyncWrapper(): def solara_test(solara_server, solara_app, page_session: "playwright.sync_api.Page"): global run_calls with solara_app("solara.test.pytest_plugin:SyncWrapper"): + # a currently open page will try to connect to solara, creating a + # new context, so we navigate away first, then close all contexts + page_session.goto("about:blank") + for key in list(solara.server.app.contexts): + try: + solara.server.app.contexts[key].close() + except: # noqa + pass + assert len(solara.server.app.contexts) == 0 page_session.goto(solara_server.base_url) run_event.wait() assert run_calls == 1