From c42595922dae2064a7434adf1dfd3cc55ab21beb Mon Sep 17 00:00:00 2001 From: x01dc Date: Tue, 28 Jul 2026 10:46:50 +0200 Subject: [PATCH] fix(devices): defer Aravis import-guard from Camera.__init__ to on_connect() Camera.__init__ raised ImportError unconditionally whenever the Aravis GObject-Introspection library wasn't importable, even with connect=False -- contradicting the module's own "lazy initialization" docstring and breaking every unit test in CI, since Aravis is a system library (not pip-installable) that CI never has installed. The test fixture builds a real AlliedVisionAravisCamera(connect=False) and only mocks camera.cam afterward, so the raise fired before mocking ever got a chance to run. Move the guard into on_connect(), mirroring IDSCamera's working pattern (its equivalent check lives in the object only built by on_connect(), never at construction time). Construction is now independent of whether Aravis is installed; on_connect() still raises the same clear error the moment something actually tries to talk to hardware. --- .../allied_vision_cameras/base_integration/camera.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/csaxs_bec/devices/allied_vision_cameras/base_integration/camera.py b/csaxs_bec/devices/allied_vision_cameras/base_integration/camera.py index 0ce200e..26e92a4 100644 --- a/csaxs_bec/devices/allied_vision_cameras/base_integration/camera.py +++ b/csaxs_bec/devices/allied_vision_cameras/base_integration/camera.py @@ -46,12 +46,6 @@ class Camera: """ def __init__(self, camera_id: str, connect: bool = True): - if Aravis is None: - raise ImportError( - "The Aravis library is not installed, or its GObject Introspection typelib" - " is missing. Please check your Python environment (PyGObject) and Aravis" - " installation." - ) self.Aravis = Aravis self.GLib = GLib self.camera_id = camera_id @@ -72,6 +66,12 @@ class Camera: def on_connect(self): """Connect to the camera and initialize it.""" + if self.Aravis is None: + raise ImportError( + "The Aravis library is not installed, or its GObject Introspection typelib" + " is missing. Please check your Python environment (PyGObject) and Aravis" + " installation." + ) if self._connected: logger.warning("Camera is already connected.") return