summaryrefslogtreecommitdiff
path: root/src/silx/gui/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/silx/gui/conftest.py')
-rw-r--r--src/silx/gui/conftest.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/silx/gui/conftest.py b/src/silx/gui/conftest.py
index 74b5c19..2e9cf0d 100644
--- a/src/silx/gui/conftest.py
+++ b/src/silx/gui/conftest.py
@@ -1,5 +1,47 @@
import pytest
+from silx.gui import qt
+from silx.gui.qt.inspect import isValid
+
+
@pytest.fixture(autouse=True)
def auto_qapp(qapp):
pass
+
+
+@pytest.fixture
+def qWidgetFactory(qapp, qapp_utils):
+ """QWidget factory as fixture
+
+ This fixture provides a function taking a QWidget subclass as argument
+ which returns an instance of this QWidget making sure it is shown first
+ and destroyed once the test is done.
+ """
+ widgets = []
+
+ def createWidget(cls, *args, **kwargs):
+ widget = cls(*args, **kwargs)
+ widget.setAttribute(qt.Qt.WA_DeleteOnClose)
+ widget.show()
+ qapp_utils.qWaitForWindowExposed(widget)
+ widgets.append(widget)
+
+ return widget
+
+ yield createWidget
+
+ qapp.processEvents()
+
+ for widget in widgets:
+ if isValid(widget):
+ widget.close()
+ qapp.processEvents()
+
+ # Wait some time for all widgets to be deleted
+ for _ in range(10):
+ validWidgets = [widget for widget in widgets if isValid(widget)]
+ if validWidgets:
+ qapp_utils.qWait(10)
+
+ validWidgets = [widget for widget in widgets if isValid(widget)]
+ assert not validWidgets, f"Some widgets were not destroyed: {validWidgets}"