test(xrayeye): keep the ellipse-ROI test items in a module-lifetime QGraphicsScene #336

Merged
holler merged 1 commits from fix/xrayeye-roi-test-gc into main 2026-10-20 15:34:37 +02:00
@@ -27,6 +27,22 @@ def _qapp():
return pg.mkQApp()
# All test ROIs go into one scene that lives for the whole module: Qt then owns the items, and the
# Python garbage collector cannot delete an unparented ROI while the next one is being built (that
# crashed PySide6 / pyqtgraph in CI with --random-order: "Fatal Python error: Segmentation fault" in
# GraphicsObject.itemChange during garbage collection).
_SCENE = None
@pytest.fixture(autouse=True, scope="module")
def _scene(_qapp):
global _SCENE
_SCENE = pg.QtWidgets.QGraphicsScene()
yield _SCENE
_SCENE.clear()
_SCENE = None
class _FakeEllipticalROI(pg.EllipseROI):
"""pg ellipse standing in for bec_widgets' EllipticalROI in isinstance checks."""
@@ -39,6 +55,7 @@ def _patch_roi_class():
def _roi(pos=(10.0, 20.0), size=(40.0, 20.0), angle=0.0):
roi = _FakeEllipticalROI(pos, size, angle=angle)
_SCENE.addItem(roi)
return roi