Skip to content

Commit cd16959

Browse files
committed
explicit emit() inside a waitSignal blocks now work
fixes #16
1 parent 19d46f8 commit cd16959

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pytestqt/_tests/test_wait_signal.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def explicit_wait(qtbot, signal, timeout):
2323
Explicit wait for the signal using blocker API.
2424
"""
2525
blocker = qtbot.waitSignal(signal, timeout)
26-
assert blocker.signal_triggered is None
26+
assert not blocker.signal_triggered
2727
blocker.wait()
2828
return blocker
2929

@@ -73,3 +73,14 @@ def test_signal_triggered(qtbot, wait_function, emit_delay, timeout,
7373
timeout = emit_delay * 4
7474
max_wait_ms = max(emit_delay, timeout)
7575
assert time.time() - start_time < (max_wait_ms / 1000.0)
76+
77+
78+
def test_explicit_emit(qtbot):
79+
"""
80+
Make sure an explicit emit() inside a waitSignal block works.
81+
"""
82+
signaller = Signaller()
83+
with qtbot.waitSignal(signaller.signal, timeout=5000) as waiting:
84+
signaller.signal.emit()
85+
86+
assert waiting.signal_triggered

pytestqt/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def __init__(self, timeout=1000):
280280
self._loop = QtCore.QEventLoop()
281281
self._signals = []
282282
self.timeout = timeout
283-
self.signal_triggered = None
283+
self.signal_triggered = False
284284

285285
def wait(self):
286286
"""
@@ -289,11 +289,12 @@ def wait(self):
289289
:raise ValueError: if no signals are connected and timeout is None; in
290290
this case it would wait forever.
291291
"""
292+
if self.signal_triggered:
293+
return
292294
if self.timeout is None and len(self._signals) == 0:
293295
raise ValueError("No signals or timeout specified.")
294296
if self.timeout is not None:
295297
QtCore.QTimer.singleShot(self.timeout, self._loop.quit)
296-
self.signal_triggered = False
297298
self._loop.exec_()
298299

299300
def connect(self, signal):
@@ -306,7 +307,6 @@ def connect(self, signal):
306307
signal.connect(self._quit_loop_by_signal)
307308
self._signals.append(signal)
308309

309-
310310
def _quit_loop_by_signal(self):
311311
"""
312312
quits the event loop and marks that we finished because of a signal.

0 commit comments

Comments
 (0)