@@ -161,12 +161,7 @@ class QtBot(object):
161
161
162
162
"""
163
163
164
- def __init__ (self , app ):
165
- """
166
- :param QApplication app:
167
- The current QApplication instance.
168
- """
169
- self ._app = app
164
+ def __init__ (self ):
170
165
self ._widgets = [] # list of weakref to QWidget instances
171
166
172
167
def _close (self ):
@@ -177,6 +172,7 @@ def _close(self):
177
172
w = w ()
178
173
if w is not None :
179
174
w .close ()
175
+ w .deleteLater ()
180
176
self ._widgets [:] = []
181
177
182
178
def addWidget (self , widget ):
@@ -230,7 +226,7 @@ def stopForInteraction(self):
230
226
if widget is not None :
231
227
widget_and_visibility .append ((widget , widget .isVisible ()))
232
228
233
- self . _app .exec_ ()
229
+ QApplication . instance () .exec_ ()
234
230
235
231
for widget , visible in widget_and_visibility :
236
232
widget .setVisible (visible )
@@ -397,7 +393,7 @@ def qtbot(qapp, request):
397
393
Make sure to call addWidget for each top-level widget you create to ensure
398
394
that they are properly closed after the test ends.
399
395
"""
400
- result = QtBot (qapp )
396
+ result = QtBot ()
401
397
no_capture = request .node .get_marker ('qt_no_exception_capture' ) or \
402
398
request .config .getini ('qt_no_exception_capture' )
403
399
if no_capture :
@@ -416,6 +412,14 @@ def pytest_addoption(parser):
416
412
'disable automatic exception capture' )
417
413
418
414
415
+ @pytest .mark .hookwrapper
416
+ def pytest_runtest_teardown ():
417
+ yield
418
+ app = QApplication .instance ()
419
+ if app is not None :
420
+ app .processEvents ()
421
+
422
+
419
423
def pytest_configure (config ):
420
424
config .addinivalue_line (
421
425
'markers' ,
0 commit comments