From 7fe792136557a72b4909bd8d8ced72e28eda9acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Ri=C3=9Fe?= Date: Sun, 14 Jan 2024 11:23:10 +0100 Subject: [PATCH] WIP --- tests/fixtures.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index cce82e8c0..393f5302c 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -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 @@ -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