Skip to content

waitSignal swallows exceptions with raising=True #59

Closed
@The-Compiler

Description

@The-Compiler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions