Skip to content

Commit e0b50cb

Browse files
authored
test: fix some flaky tests (#488)
* fix flaky tests * skip stack viewer on py 3.14 * fix flaky tests
1 parent bcbe715 commit e0b50cb

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dev = [
8585
"mypy>=1.15.0",
8686
"pdbpp>=0.11.6 ; sys_platform != 'win32'",
8787
"pre-commit-uv >=4.1.0",
88+
"prek>=0.3.1",
8889
"pyqt6>=6.9.0",
8990
"rich>=14.0.0",
9091
"ruff>=0.11.8",

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _run_after_each_test(request: FixtureRequest, qapp: QApplication) -> Iterato
138138
return
139139
remaining = qapp.topLevelWidgets()
140140
if len(remaining) > nbefore:
141-
if type(remaining[0]).__name__ in {"ImagePreview", "SnapButton"}:
141+
if any(type(w).__name__ in {"ImagePreview", "SnapButton"} for w in remaining):
142142
# I have no idea why, but the ImagePreview widget is leaking.
143143
# And it only came with a seemingly unrelated
144144
# https://github.com/pymmcore-plus/pymmcore-widgets/pull/90

tests/test_pixel_config_widget.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,15 @@ def test_pixel_config_wdg_prop_change(qtbot: QtBot, global_mmcore: CMMCorePlus):
175175
assert viewer_wdg.value() == "Nikon 10X S Fluor"
176176
assert wdg._props_selector.value() == [("Objective", "Label", "Nikon 10X S Fluor")]
177177

178-
# row 67 is the ("Objective", "Label") property
179-
prop_wdg = wdg._props_selector._prop_table.cellWidget(67, 1)
178+
# find the row for ("Objective", "Label") dynamically
179+
prop_table = wdg._props_selector._prop_table
180+
obj_row = next(
181+
r
182+
for r in range(prop_table.rowCount())
183+
if (p := prop_table.item(r, 0).data(prop_table.PROP_ROLE))
184+
and (p.device, p.name) == ("Objective", "Label")
185+
)
186+
prop_wdg = prop_table.cellWidget(obj_row, 1)
180187
assert prop_wdg.value() == "Nikon 10X S Fluor"
181188

182189
viewer_wdg.setValue("Nikon 40X Plan Fluor ELWD")

tests/test_prop_widget.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def test_property_widget(global_mmcore: CMMCorePlus, qtbot) -> None:
5353
val = allowed[-1]
5454
elif wdg.propertyType() in {PropertyType.Integer, PropertyType.Float}:
5555
val = _vals.get(prop, 1)
56+
if core.hasPropertyLimits(dev, prop):
57+
lo = core.getPropertyLowerLimit(dev, prop)
58+
hi = core.getPropertyUpperLimit(dev, prop)
59+
val = max(lo, min(hi, val))
5660
else:
5761
val = "some string"
5862

tests/test_stack_viewer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from typing import TYPE_CHECKING
45

56
import pytest
@@ -18,7 +19,7 @@
1819
from pytestqt.qtbot import QtBot
1920

2021

21-
if qtpy.API_NAME.startswith("PySide"):
22+
if qtpy.API_NAME.startswith("PySide") or sys.version_info >= (3, 14):
2223
pytest.skip(
2324
"Fails too often on CI. Usually (but not only) PySide6", allow_module_level=True
2425
)

0 commit comments

Comments
 (0)