Skip to content

Commit 6540797

Browse files
committed
Call processEvents after each test teardown
Also, QtBot does not keep a reference to QApplication
1 parent a3a382f commit 6540797

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pytestqt/plugin.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,7 @@ class QtBot(object):
161161
162162
"""
163163

164-
def __init__(self, app):
165-
"""
166-
:param QApplication app:
167-
The current QApplication instance.
168-
"""
169-
self._app = app
164+
def __init__(self):
170165
self._widgets = [] # list of weakref to QWidget instances
171166

172167
def _close(self):
@@ -177,6 +172,7 @@ def _close(self):
177172
w = w()
178173
if w is not None:
179174
w.close()
175+
w.deleteLater()
180176
self._widgets[:] = []
181177

182178
def addWidget(self, widget):
@@ -230,7 +226,7 @@ def stopForInteraction(self):
230226
if widget is not None:
231227
widget_and_visibility.append((widget, widget.isVisible()))
232228

233-
self._app.exec_()
229+
QApplication.instance().exec_()
234230

235231
for widget, visible in widget_and_visibility:
236232
widget.setVisible(visible)
@@ -397,7 +393,7 @@ def qtbot(qapp, request):
397393
Make sure to call addWidget for each top-level widget you create to ensure
398394
that they are properly closed after the test ends.
399395
"""
400-
result = QtBot(qapp)
396+
result = QtBot()
401397
no_capture = request.node.get_marker('qt_no_exception_capture') or \
402398
request.config.getini('qt_no_exception_capture')
403399
if no_capture:
@@ -416,6 +412,14 @@ def pytest_addoption(parser):
416412
'disable automatic exception capture')
417413

418414

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+
419423
def pytest_configure(config):
420424
config.addinivalue_line(
421425
'markers',

0 commit comments

Comments
 (0)