diff --git a/solara/test/pytest_plugin.py b/solara/test/pytest_plugin.py index 9ed4add44..e6d195812 100644 --- a/solara/test/pytest_plugin.py +++ b/solara/test/pytest_plugin.py @@ -171,32 +171,35 @@ def solara_test(solara_server, solara_app, page_session: "playwright.sync_api.Pa with solara_app("solara.test.pytest_plugin:SyncWrapper"): page_session.goto(solara_server.base_url) run_event.wait() - assert run_calls == 1 - keys = list(solara.server.app.contexts) - assert len(keys) == 1, "expected only one context, got %s" % keys - context = solara.server.app.contexts[keys[0]] - with context: - test_output_warmup = widgets.Output() - test_output = widgets.Output() - try: - page_session.locator("text=Test in solara").wait_for() - context.container.children[0].children[1].children[1].children = [test_output_warmup] # type: ignore - with test_output_warmup: - warmup() - button = page_session.locator(".solara-warmup-widget") - button.wait_for() - page_session.evaluate("document.fonts.ready") - button.click() - button.wait_for(state="detached") - page_session.evaluate("document.fonts.ready") - context.container.children[0].children[1].children[1].children = [test_output] # type: ignore - with test_output: - yield - finally: - test_output.close() - run_event.clear() - test_output = None - run_calls = 0 + try: + assert run_calls == 1 + keys = list(solara.server.app.contexts) + assert len(keys) == 1, "expected only one context, got %s" % keys + context = solara.server.app.contexts[keys[0]] + with context: + test_output_warmup = widgets.Output() + test_output = widgets.Output() + try: + page_session.locator("text=Test in solara").wait_for() + context.container.children[0].children[1].children[1].children = [test_output_warmup] # type: ignore + with test_output_warmup: + warmup() + button = page_session.locator(".solara-warmup-widget") + button.wait_for() + page_session.evaluate("document.fonts.ready") + button.click() + button.wait_for(state="detached") + page_session.evaluate("document.fonts.ready") + context.container.children[0].children[1].children[1].children = [test_output] # type: ignore + with test_output: + yield + finally: + test_output.close() + test_output_warmup.close() + finally: + run_event.clear() + test_output = None + run_calls = 0 class ServerVoila(ServerBase):