1414import os
1515import os .path as osp
1616import platform
17- import sys
1817import subprocess
18+ import sys
1919
20- from qtpy import QtWidgets as QW
21- from qtpy import QtGui as QG
2220from qtpy import QtCore as QC
21+ from qtpy import QtGui as QG
22+ from qtpy import QtWidgets as QW
2323
2424import qwt
25- from qwt import qthelpers as qth
2625from qwt import QwtPlot
27-
26+ from qwt import qthelpers as qth
2827
2928QT_API = os .environ ["QT_API" ]
3029
@@ -186,7 +185,9 @@ def add_test(self, fname):
186185 bname = osp .basename (fname )
187186 button = QW .QToolButton (self )
188187 button .setToolButtonStyle (QC .Qt .ToolButtonTextUnderIcon )
189- shot = osp .join (TEST_PATH , "data" , bname .replace (".py" , ".png" ).replace ("test_" , "" ))
188+ shot = osp .join (
189+ TEST_PATH , "data" , bname .replace (".py" , ".png" ).replace ("test_" , "" )
190+ )
190191 if osp .isfile (shot ):
191192 button .setIcon (QG .QIcon (shot ))
192193 else :
@@ -264,6 +265,14 @@ def take_screenshot(widget):
264265 qth .take_screenshot (widget , osp .join (TEST_PATH , "data" , bname ), quit = True )
265266
266267
268+ def close_widgets_and_quit () -> None :
269+ """Close Qt top level widgets and quit Qt event loop"""
270+ QW .QApplication .processEvents ()
271+ for widget in QW .QApplication .instance ().topLevelWidgets ():
272+ assert widget .close ()
273+ QC .QTimer .singleShot (0 , QW .QApplication .instance ().quit )
274+
275+
267276def test_widget (widget_class , size = None , title = None , options = True ):
268277 """Test widget"""
269278 widget_name = widget_class .__name__
@@ -300,9 +309,9 @@ def test_widget(widget_class, size=None, title=None, options=True):
300309 if test_env .screenshots :
301310 QC .QTimer .singleShot (1000 , lambda : take_screenshot (widget_of_interest ))
302311 elif test_env .unattended :
303- QC .QTimer .singleShot (0 , QW . QApplication . instance (). quit )
312+ QC .QTimer .singleShot (0 , close_widgets_and_quit )
304313 if QT_API == "pyside6" :
305314 app .exec ()
306315 else :
307316 app .exec_ ()
308- return app
317+ return app
0 commit comments