Skip to content

Commit

Permalink
test(pytest): always resture run_calls to 0 so follow up tests do not…
Browse files Browse the repository at this point in the history
… fail
  • Loading branch information
maartenbreddels committed Aug 30, 2023
1 parent a9f0970 commit f366a02
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions solara/test/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,26 @@ def solara_test(solara_server, solara_app, page_session: "playwright.sync_api.Pa
pass
assert len(solara.server.app.contexts) == 0
page_session.goto(solara_server.base_url)
run_event.wait()
# for some reason, we still get 2 context sometimes, it could be the reconnection
# code of the websocket of the previous page still running. We wait a bit
# till we end up with only one context
n = 0
# we wait till the all contexts are closed
while len(solara.server.app.contexts) != 1:
page_session.wait_for_timeout(100)
n += 1
if n > 50:
raise RuntimeError("Timeout waiting for a single context")

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:
try:
run_event.wait()
# for some reason, we still get 2 context sometimes, it could be the reconnection
# code of the websocket of the previous page still running. We wait a bit
# till we end up with only one context
n = 0
# we wait till the all contexts are closed
while len(solara.server.app.contexts) != 1:
page_session.wait_for_timeout(100)
n += 1
if n > 50:
raise RuntimeError("Timeout waiting for a single context, contexts found: %r", list(solara.server.app.contexts))

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()
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:
Expand All @@ -212,11 +212,10 @@ def solara_test(solara_server, solara_app, page_session: "playwright.sync_api.Pa
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
finally:
run_calls = 0
run_event.clear()


class ServerVoila(ServerBase):
Expand Down

0 comments on commit f366a02

Please sign in to comment.