Skip to content

Commit ddfce3c

Browse files
committed
Handle exceptions correctly inside waitSignal* with blocks
Fix #59
1 parent b04367f commit ddfce3c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pytestqt/_tests/test_wait_signal.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,25 @@ def check(self, timeout, *delays):
217217
return StopWatch()
218218

219219

220+
@pytest.mark.parametrize('multiple, raising',
221+
[(True, True), (True, False), (False, True),
222+
(False, False)])
223+
def test_wait_signals_handles_exceptions(qtbot, multiple, raising):
224+
"""
225+
Make sure waitSignal handles exceptions correctly.
226+
"""
227+
class TestException(Exception):
228+
pass
229+
230+
signaller = Signaller()
231+
232+
if multiple:
233+
func = qtbot.waitSignals
234+
arg = [signaller.signal, signaller.signal_2]
235+
else:
236+
func = qtbot.waitSignal
237+
arg = signaller.signal
238+
239+
with pytest.raises(TestException):
240+
with func(arg, timeout=10, raising=raising):
241+
raise TestException

pytestqt/plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ def __enter__(self):
377377
return self
378378

379379
def __exit__(self, type, value, traceback):
380-
self.wait()
380+
if value is None:
381+
# only wait if no exception happened inside the "with" block
382+
self.wait()
381383

382384

383385
class SignalBlocker(_AbstractSignalBlocker):

0 commit comments

Comments
 (0)