Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss committed Feb 15, 2024
1 parent b400942 commit b945b80
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,29 @@ def _fail_if_open_message_boxes_left():
def _fail_if_any_widgets_left_open(qapp, qtbot):
yield

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)
# 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=}"
# try:
# qtbot.wait_until(assert_no_widgets_left_open)
# except AssertionError:
# pytest.xfail()


@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 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 +94,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 b945b80

Please sign in to comment.