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

Fix flaky dims playback test by waiting for playing condition #5414

Merged
merged 9 commits into from Dec 20, 2022

Conversation

andy-sweet
Copy link
Member

Description

Before this change test_qt_dims.py::test_play_button tried to wait for QtDims._animation_thread.started, which had a few issues.

  1. waitSignal returns a SignalBlocker, but does not actually wait. Based on the pytest-qt docs you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
  2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
  3. QtDims._animation_thread is None before the button has been clicked.

This recently caused a failure on what should be an unrelated PR. I don't know enough about pytest-qt to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use waitUntil to wait on QtDims.is_playing instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373

Type of change

  • Bug-fix (non-breaking change which fixes an issue)

@github-actions github-actions bot added qt Relates to qt tests Something related to our tests labels Dec 16, 2022
@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #5414 (0b0e2a6) into main (549aabb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5414   +/-   ##
=======================================
  Coverage   89.09%   89.09%           
=======================================
  Files         597      597           
  Lines       50612    50614    +2     
=======================================
+ Hits        45091    45097    +6     
+ Misses       5521     5517    -4     
Impacted Files Coverage Δ
napari/_qt/widgets/qt_dims.py 96.85% <ø> (-0.02%) ⬇️
napari/_qt/widgets/qt_dims_slider.py 94.19% <ø> (ø)
napari/_qt/widgets/_tests/test_qt_dims.py 100.00% <100.00%> (ø)
napari/utils/theme.py 92.85% <0.00%> (+0.59%) ⬆️
napari/utils/info.py 81.44% <0.00%> (+1.03%) ⬆️
napari/_qt/__init__.py 56.66% <0.00%> (+6.66%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@andy-sweet
Copy link
Member Author

@Czaki : I assigned you this because you worked on similar things recently.

Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
@andy-sweet
Copy link
Member Author

Thanks for the review! Will merge this after 24 hours.

@andy-sweet andy-sweet merged commit b9a15ee into napari:main Dec 20, 2022
@andy-sweet andy-sweet deleted the fix-qtbot-waitSignal branch December 20, 2022 23:11
melissawm pushed a commit to melissawm/napari that referenced this pull request Jan 11, 2023
…#5414)

Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from napari#5373
@Czaki Czaki mentioned this pull request Jun 7, 2023
@andy-sweet andy-sweet added this to the 0.4.18 milestone Jun 14, 2023
@andy-sweet
Copy link
Member Author

Assigned the 0.4.18 milestone because although this is mostly about tests and shouldn't matter, it also removes an unnecessary print and and comment. Alternatively, bring those changes into 0.4.18 with a new commit.

Czaki pushed a commit that referenced this pull request Jun 16, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 17, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 18, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 19, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Czaki pushed a commit that referenced this pull request Jun 21, 2023
Before this change `test_qt_dims.py::test_play_button` tried to wait for `QtDims._animation_thread.started`, which had a few issues.

1. `waitSignal` returns a `SignalBlocker`, but does not actually wait. Based on [the `pytest-qt` docs](https://pytest-qt.readthedocs.io/en/latest/signals.html#) you should typically use that as a context manager to wait, where the code with in the context should eventually cause the signal to be emitted.
2. The intent is to start waiting after mouse click has occurred, but it's possible (though unlikely) that the signal has already been emitted.
3. `QtDims._animation_thread` is `None` before the button has been clicked.

This recently caused [a failure on what should be an unrelated PR](https://github.com/napari/napari/actions/runs/3709270881/jobs/6287719643#step:8:379). I don't know enough about `pytest-qt` to confidently explain the failure - but my guess is that the two mouse clicks are being registered as one that starts playback, but does not stop it.

The fix here is to use `waitUntil` to wait on `QtDims.is_playing` instead. This makes the test slightly less inefficient, but also makes it simpler and less dependent on implementation details.

I also removed a couple of timeout values because the default is 5000 (milliseconds) anyway - if waiting 5 seconds didn't work, waiting another 2 seconds is almost always just wishful thinking.

Finally, I removed some other leftovers from #5373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants