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

Replace occurrences of tests.utils.wait_until_signal with qtbot.wait_signal #2156

Closed
matrss opened this issue Jan 18, 2024 · 2 comments · Fixed by #2247
Closed

Replace occurrences of tests.utils.wait_until_signal with qtbot.wait_signal #2156

matrss opened this issue Jan 18, 2024 · 2 comments · Fixed by #2247
Labels
Milestone

Comments

@matrss
Copy link
Collaborator

matrss commented Jan 18, 2024

The wait_until_signal function has the limitation that it starts listening for a signal only after the code that should emit that signal was called. This means there is a time window in between these calls in which the signal could be emitted but is not seen by the wait. I.e. a race condition.

The wait_signal context manager from pytest-qt does not have this issue because it wraps the code that is expected to emit the given signal in a with block and therefore starts listening before the signal has a chance to be emitted.

@matrss matrss added the tests label Jan 18, 2024
@ReimarBauer ReimarBauer added this to the 9.0.0 milestone Jan 22, 2024
@rohit2p
Copy link
Contributor

rohit2p commented Feb 25, 2024

@matrss correct me if i am wrong, according Recommended approach i need to replace wait_until_signal function with qtbot.wait_signal within with blocks.
so for that i need make changes in this this files:-

by replacing with this for example:

with qtbot.wait_signal(self.wms_control.cpdig.canceled):
    # I'll adjust the signal names (cpdig.canceled, image_displayed, etc.) to match the actual signals

while doing this ill be importing qtbot like this:
from pytestqt.qtbot import qtbot

But, what do i do with the function wait_until_signal in utils.pyshould i remove it since we'll be using qtbot.wait_signal insted.
or is their anything more that should be done to solve this issue ? just wanted to confirm before making the changes.

@matrss
Copy link
Collaborator Author

matrss commented Feb 26, 2024

@matrss correct me if i am wrong, according Recommended approach i need to replace wait_until_signal function with qtbot.wait_signal within with blocks. so for that i need make changes in this this files:- by replacing with this for example:

with qtbot.wait_signal(self.wms_control.cpdig.canceled):
    # I'll adjust the signal names (cpdig.canceled, image_displayed, etc.) to match the actual signals

Yes, exactly.

while doing this ill be importing qtbot like this:
from pytestqt.qtbot import qtbot

No, qtbot is a pytest fixture (https://docs.pytest.org/en/stable/how-to/fixtures.html#how-to-fixtures). That means it just needs to be added as a function argument to the test function, if it isn't there already. You can grep for qtbot in tests/ to see how it is used in other places.

But, what do i do with the function wait_until_signal in utils.pyshould i remove it since we'll be using qtbot.wait_signal insted.

When it is no longer used anywhere it can be removed.

or is their anything more that should be done to solve this issue ? just wanted to confirm before making the changes.

This should be all.

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

Successfully merging a pull request may close this issue.

3 participants