Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss committed Mar 21, 2024
1 parent 866d733 commit 9e2a36c
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,16 @@ def _fail_if_any_widgets_left_open(qapp, qtbot):
def assert_no_widgets_left_open():
widgets = set(qapp.topLevelWindows() + qapp.topLevelWidgets())
assert len(widgets) == 0, f"There are Qt widgets left open at the end of the test!\n{widgets=}"

qtbot.wait_until(assert_no_widgets_left_open)


@contextmanager
def _close_remaining_widgets(qapp):
def _close_remaining_widgets(qapp, qtbot):
yield
# Try to close all remaining widgets after each test
for qobject in set(qapp.topLevelWindows() + qapp.topLevelWidgets()):
try:
qobject.destroy()
# Some objects deny permission, pass in that case
except RuntimeError:
pass
for widget in qapp.topLevelWidgets():
widget.close()
widget.deleteLater()
qtbot.wait_until(lambda: len(qapp.topLevelWidgets()) == 0)


@pytest.fixture
Expand All @@ -88,7 +84,7 @@ def qtbot(qapp, qtbot):
Afterwards it will destroy all remaining top-level widgets to make sure that they do
not affect the following tests.
"""
with _close_remaining_widgets(qapp), \
with _close_remaining_widgets(qapp, qtbot), \
_fail_if_any_widgets_left_open(qapp, qtbot), \
_fail_if_open_message_boxes_left():
yield qtbot
Expand Down

0 comments on commit 9e2a36c

Please sign in to comment.