How to test PyQt/PySide signals?
<p>I'm trying to test a class that takes "events" from another library and re-dispatches them as Signals/pyqtSignals.  </p>

<p>I'm trying to test it by:</p>

<ol>
<li>Connecting a handler.</li>
<li>Performing some action that should trigger the event (and thus, the Signal/pyqtSignal to be emitted, which should call the handler).</li>
<li>Checking to see if the handler was called.</li>
</ol>

<p>But the handler never gets called.  Or at least it's not getting called by the time I check for it.  If I run the lines of the test function one-by-one in a console, the test is successful.</p>

<p>I think the problem is that the Signals aren't getting processed until after the test function completes, but if that's the case, how would I go about testing them?</p>

<p>Here is an example of how I'm trying to test:</p>

<pre><code>from mock import Mock


def test_object():
    obj = MyObject()
    handler = Mock()

    # This connects handler to a Signal/pyqtSignal
    obj.connect('event_type', handler)

    # This should trigger that signal
    obj.do_some_stuff()

    # This fails (call_count is 0)
    assert handler.call_count = 1

    # This will also fail (call_count is 0)
    QtCore.QCoreApplication.instance().processEvents()
    assert handler.call_count = 1
</code></pre>