Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitSignal swallows exceptions with raising=True #59

Closed
The-Compiler opened this issue Jun 11, 2015 · 6 comments
Closed

waitSignal swallows exceptions with raising=True #59

The-Compiler opened this issue Jun 11, 2015 · 6 comments

Comments

@The-Compiler
Copy link
Member

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
@nicoddemus
Copy link
Member

Fixed, thanks! 😄

The problem was on the __exit__ method, it should not try to call wait if an exception has occurred, as then the signal might never be triggered and then a timeout would occur, overriding the first exception.

@The-Compiler
Copy link
Member Author

That was an easier fix than I thought - thanks! 👍

What if an exception happens during wait? Will that be picked up by the custom excepthook and displayed even when the SignalTimeoutError occurs?

@nicoddemus
Copy link
Member

Yes the problem was that it was overwriting the original exception. If
there's an exception inside wait(), it will prevent timeout from even being
reached. 😄

Em sex, 12 de jun de 2015 01:36, Florian Bruhin notifications@github.com
escreveu:

That was an easier fix than I thought - thanks! [image: 👍]

What if an exception happens during wait? Will that be picked up by the
custom excepthook and displayed even when the SignalTimeoutError occurs?


Reply to this email directly or view it on GitHub
#59 (comment)
.

@nicoddemus
Copy link
Member

nicoddemus commented Jun 17, 2015 via email

@The-Compiler
Copy link
Member Author

It sounds like you're replying to the wrong mail - this is pytest-qt 😉

@nicoddemus
Copy link
Member

Oh dear. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants