Skip to content

Commit

Permalink
change when we perform GC run in test_webview
Browse files Browse the repository at this point in the history
This makes it clear that we don't collect the WebView from the current test run (which is still referenced by fixtures) but from the previous run.
  • Loading branch information
samschott committed Aug 18, 2023
1 parent 2104495 commit e87562c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions testbed/tests/widgets/test_webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ async def on_load():

@pytest.fixture
async def widget(on_load):
if toga.platform.current_platform == "linux":
# On Gtk, ensure that the WebView from a previous test run is garbage collected.
# This prevents a segfault at GC time likely coming from the test suite running
# in a thread and Gtk WebViews sharing resources between instances. We perform
# the GC run here since pytest fixtures make earlier cleanup difficult.
gc.collect()

widget = toga.WebView(style=Pack(flex=1), on_webview_load=on_load)
# We shouldn't be able to get a callback until at least one tick of the event loop
# has completed.
Expand All @@ -104,14 +111,7 @@ async def widget(on_load):
else:
raise

yield widget

if toga.platform.current_platform == "linux":
# On Gtk, ensure that the WebView is garbage collection before the next test
# case. This prevents a segfault at GC time likely coming from the test suite
# running in a thread and Gtk WebViews sharing resources between instances.
del widget
gc.collect()
return widget


async def test_set_url(widget, probe, on_load):
Expand Down

0 comments on commit e87562c

Please sign in to comment.