Skip to content

Commit 442e485

Browse files
committed
Fix flaky progress callback test for PyQt6 compatibility
1 parent 78b2813 commit 442e485

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

tests/test_progress_signal.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def test_progress_callback_integration(make_napari_viewer, qtbot):
6565

6666
# Mock the actual motion correction to simulate progress callbacks
6767
# compensate_arr is imported inside the worker function, so we need to patch it there
68-
with patch('pyflowreg.motion_correction.compensate_arr.compensate_arr') as mock_compensate:
68+
# Also patch add_image to prevent teardown errors in headless Qt6
69+
with patch('pyflowreg.motion_correction.compensate_arr.compensate_arr') as mock_compensate, \
70+
patch.object(widget.viewer, 'add_image', lambda *a, **k: None):
6971
# Simulate motion correction with progress callbacks
7072
def mock_correction(video, ref, options, progress_callback=None):
7173
# Simulate processing frames with progress updates
@@ -74,17 +76,20 @@ def mock_correction(video, ref, options, progress_callback=None):
7476
if progress_callback:
7577
progress_callback(i + 1, total_frames)
7678
time.sleep(0.01) # Small delay to simulate processing
77-
79+
7880
# Return mock results
7981
return video, None # Return original as "corrected" and no flow
80-
82+
8183
mock_compensate.side_effect = mock_correction
82-
84+
8385
# Start motion correction
8486
widget._on_start_clicked()
85-
86-
# Wait for processing to complete
87-
qtbot.waitUntil(lambda: len(progress_spy) >= 1, timeout=1000)
87+
88+
# Wait until we actually see 100% progress (not just "some" progress)
89+
qtbot.waitUntil(
90+
lambda: len(progress_spy) > 0 and int(progress_spy[-1][0]) >= 100,
91+
timeout=5000
92+
)
8893

8994
# Check that progress signals were emitted
9095
signal_count = len(progress_spy)
@@ -97,7 +102,7 @@ def mock_correction(video, ref, options, progress_callback=None):
97102

98103
# Check final progress is 100%
99104
if signal_count > 0:
100-
final_progress = progress_spy[signal_count - 1][0]
105+
final_progress = int(progress_spy[signal_count - 1][0])
101106
assert final_progress == 100, f"Final progress was {final_progress}, expected 100"
102107

103108

0 commit comments

Comments
 (0)