2
2
import functools
3
3
import sys
4
4
import traceback
5
+ import weakref
5
6
6
7
import pytest
7
8
@@ -173,7 +174,9 @@ def _close(self):
173
174
Clear up method. Called at the end of each test that uses a ``qtbot`` fixture.
174
175
"""
175
176
for w in self ._widgets :
176
- w .close ()
177
+ w = w ()
178
+ if w is not None :
179
+ w .close ()
177
180
self ._widgets [:] = []
178
181
179
182
def addWidget (self , widget ):
@@ -184,7 +187,9 @@ def addWidget(self, widget):
184
187
:param QWidget widget:
185
188
Widget to keep track of.
186
189
"""
187
- self ._widgets .append (widget )
190
+ self ._widgets .append (weakref .ref (widget ))
191
+
192
+ add_widget = addWidget # pep-8 alias
188
193
189
194
def waitForWindowShown (self , widget ):
190
195
"""
@@ -197,6 +202,8 @@ def waitForWindowShown(self, widget):
197
202
"""
198
203
QtTest .QTest .qWaitForWindowShown (widget )
199
204
205
+ wait_for_window_shown = waitForWindowShown # pep-8 alias
206
+
200
207
def stopForInteraction (self ):
201
208
"""
202
209
Stops the current test flow, letting the user interact with any visible widget.
@@ -209,12 +216,15 @@ def stopForInteraction(self):
209
216
210
217
.. note:: As a convenience, it is also aliased as `stop`.
211
218
"""
212
- widget_visibility = [widget .isVisible () for widget in self ._widgets ]
219
+ widget_and_visibility = []
220
+ for weak_widget in self ._widgets :
221
+ widget = weak_widget ()
222
+ if widget is not None :
223
+ widget_and_visibility .append ((widget , widget .isVisible ()))
213
224
214
225
self ._app .exec_ ()
215
226
216
- for index , visible in enumerate (widget_visibility ):
217
- widget = self ._widgets [index ]
227
+ for widget , visible in widget_and_visibility :
218
228
widget .setVisible (visible )
219
229
220
230
stop = stopForInteraction
@@ -256,6 +266,8 @@ def waitSignal(self, signal=None, timeout=1000):
256
266
blocker .connect (signal )
257
267
return blocker
258
268
269
+ wait_signal = waitSignal # pep-8 alias
270
+
259
271
260
272
class SignalBlocker (object ):
261
273
0 commit comments