When qtbot.waitSignal(..., raising=True) is used and an exception in the with-block happens (which causes the signal to not be emitted), it's silently ignored and SignalTimeoutError is raised instead.
I don't really know what the best way to fix this would be (because of the existing Qt exception capturing), but I have a test case:
diff --git a/pytestqt/_tests/test_wait_signal.py b/pytestqt/_tests/test_wait_signal.py
index 13a78c7..cd5ea57 100644
--- a/pytestqt/_tests/test_wait_signal.py
+++ b/pytestqt/_tests/test_wait_signal.py
@@ -10,6 +10,29 @@ class Signaller(QtCore.QObject):
signal_2 = Signal()
+class TestException(Exception):
+ pass
+
+
+@pytest.mark.parametrize('multiple', [True, False])
+def test_raising_other_exception(qtbot, multiple):
+ """
+ Make sure waitSignal with raising=True handles exceptions correctly.
+ """
+ signaller = Signaller()
+
+ if multiple:
+ func = qtbot.waitSignals
+ arg = [signaller.signal, signaller.signal_2]
+ else:
+ func = qtbot.waitSignal
+ arg = signaller.signal
+
+ with pytest.raises(TestException):
+ with func(arg, timeout=10, raising=True):
+ raise TestException
+
+
def test_signal_blocker_exception(qtbot):
"""
Make sure waitSignal without signals and timeout doesn't hang, but raises
When
qtbot.waitSignal(..., raising=True)is used and an exception in the with-block happens (which causes the signal to not be emitted), it's silently ignored andSignalTimeoutErroris raised instead.I don't really know what the best way to fix this would be (because of the existing Qt exception capturing), but I have a test case: