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

Behaviour of waitSignal #16

Closed
baudren opened this issue Sep 10, 2014 · 6 comments
Closed

Behaviour of waitSignal #16

baudren opened this issue Sep 10, 2014 · 6 comments

Comments

@baudren
Copy link

baudren commented Sep 10, 2014

Problem description

I am having troubles with understanding how to use the functionality qtbot.waitSignal. I followed the documentation but there must be something I am missing.

It seems that a direct call to the emit method of a given signal does not trigger a block with qtbot.waitSignal(... to validate.

I found the problem by testing my application, checking if a button was sending a signal, and noted that the waitSignal was always hitting the timeout. I extracted what I think is a bug, but might be to my very new discovery of signals and slots.

What I expected / what I get

in a file test_sample.py:

from PySide.QtCore import QObject, Signal

class Simple(QObject):
    signal = Signal()

def test_Qt(qtbot):
    simple = Simple()

    with qtbot.waitSignal(simple.signal, timeout=1000) as waiting:
        simple.signal.emit()

    assert waiting.signal_triggered

Running py.test on this file results in an AssertionError, because waiting.signal_triggered is False. I expected the emit method to cause waiting to see the signal being emitted.

Possible things I might do wrong

Since I am new to this signal/slot business, I might be overlooking some essential facts.

  • As a zen master would ask, is the signal truly fired if no slot is there to listen to it?
  • Could it be that it is that slow to fire a signal?
  • Is the emit code somehow placed at the wrong spot?

Thank you for enlightening me, and thanks for sharing such a useful work, by the way. Testing GUI applications without this would be a massive pain.

Configuration

I am using Python 2.7.5, pytest 1.4.24, and PySide 1.2.2, on a Linux Mint 16.

@nicoddemus
Copy link
Member

Hi,

Ouch, you found a bug! 😅

Usually the code inside a waitSignal block schedules an event that will be processed in the next event loop, for example:

def test_window(qtbot, widget):
    with qtbot.waitSignal(app.worker.finished, timeout=10000) as blocker:
        # start() will schedule the signal to be emitted in the next event loop
        app.worker.start() 

but your example is triggering it immediately inside the block.

I'm working on a fix and will publish a new release.

Many thanks! 😄
Cheers,

@nicoddemus
Copy link
Member

Published 1.2.1. Thanks again! 😄

@baudren
Copy link
Author

baudren commented Sep 11, 2014

Wow, thanks to you for such a quick reaction! Looking forward to playtest my application, now!

@nicoddemus
Copy link
Member

Nice, thanks again! 😄
Em 11/09/2014 04:11, "baudren" [email protected] escreveu:

Wow, thanks to you for such a quick reaction! Looking forward to playtest
my application, now!


Reply to this email directly or view it on GitHub
https://github.com/nicoddemus/pytest-qt/issues/16#issuecomment-55228082.

@jdreaver
Copy link
Member

I just encountered this bug, and was about to make a fix. Next thing I know it's already fixed! I can't believe we left instantaneous signals out of our original tests for this feature. Thanks @baudren and @nicoddemus!

@nicoddemus
Copy link
Member

@jdreaver I don't believe it either, hehehe! 😅

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

3 participants