From f2fa1e4661cd9d7fc15676f4faaee1a52a4f76b1 Mon Sep 17 00:00:00 2001 From: Ivo Vellekoop Date: Fri, 11 Oct 2024 16:29:22 +0200 Subject: [PATCH] replaced importorskip to all use safe_import --- tests/test_camera.py | 12 +++++++----- tests/test_scanning_microscope.py | 12 ++++++++---- tests/test_slm.py | 10 +++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/test_camera.py b/tests/test_camera.py index 2889a4a..77f659d 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -1,11 +1,13 @@ import pytest -pytest.importorskip( - "harvesters", - reason="harvesters is required for the Camera module, install with pip install harvesters", -) +from ..openwfs.devices import Camera, safe_import + +harvesters = safe_import("harvesters", "harvesters") +if not harvesters: + pytest.skip( + "harvesters is required for the Camera module, install with pip install harvesters", allow_module_level=True + ) -from ..openwfs.devices import Camera cti_path = R"C:\Program Files\Basler\pylon 7\Runtime\x64\ProducerU3V.cti" diff --git a/tests/test_scanning_microscope.py b/tests/test_scanning_microscope.py index 83e8e5f..74897e7 100644 --- a/tests/test_scanning_microscope.py +++ b/tests/test_scanning_microscope.py @@ -2,10 +2,14 @@ import numpy as np import pytest -pytest.importorskip( - "nidaqmx", - reason="nidaqmx is required for the ScanningMicroscope module, install with pip install nidaqmx", -) +from ..openwfs.devices import safe_import + +nidaqmx = safe_import("nidaqmx", "nidaq") +if not nidaqmx: + pytest.skip( + "nidaqmx is required for the ScanningMicroscope module, install with pip install nidaqmx", + allow_module_level=True, + ) from ..openwfs.devices import ScanningMicroscope, Axis from ..openwfs.devices.galvo_scanner import InputChannel diff --git a/tests/test_slm.py b/tests/test_slm.py index 85ec3c8..bcb44ac 100644 --- a/tests/test_slm.py +++ b/tests/test_slm.py @@ -4,10 +4,14 @@ import cv2 import pytest -pytest.importorskip("glfw", reason="GLFW is required for the ScanningMicroscope module") -pytest.importorskip("OpenGL.GL", reason="PyOpenGL is required for OpenGL rendering") +from ..openwfs.devices import safe_import + +glfw = safe_import("glfw", "glfw") +OpenGL = safe_import("OpenGL", "OpenGL") +if not glfw or not OpenGL: + pytest.skip("GLFW and PyOpenGL are required for the test_slm module", allow_module_level=True) + -import glfw import numpy as np # for debugging