Skip to content

Commit

Permalink
fix: make solara_test fixture not fail subsequent tests
Browse files Browse the repository at this point in the history
If the test failed once, it will fail all subsequent tests because
it did not do a proper cleanup.
  • Loading branch information
maartenbreddels committed Oct 5, 2023
1 parent 522c274 commit 800f751
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions solara/test/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 800f751

Please sign in to comment.