From 9803f2cc105d280113a5853a040eb4ef7a7c5232 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Wed, 4 Oct 2023 21:01:03 +0200 Subject: [PATCH] fix: make solara_test fixture not fail subsequent tests If the test failed once, it will fail all subsequent tests because it did not do a proper cleanup. --- solara/test/pytest_plugin.py | 55 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 26 deletions(-) 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):