File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed
Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 2121from __future__ import annotations
2222
2323import os
24- from collections .abc import Generator
2524from contextlib import contextmanager
25+ from typing import Generator
2626
27+ import pytest
2728from guidata .guitest import run_testlauncher
2829
2930import cdl .config # Loading icons
@@ -81,6 +82,17 @@ def cdltest_app_context(
8182 win .close ()
8283
8384
85+ @contextmanager
86+ def skip_if_opencv_missing () -> Generator [None , None , None ]:
87+ """Skip test if OpenCV is not available"""
88+ try :
89+ yield
90+ except ImportError as exc :
91+ if "cv2" in str (exc ).lower ():
92+ pytest .skip ("OpenCV not available, skipping test" )
93+ raise exc
94+
95+
8496def take_plotwidget_screenshot (panel : SignalPanel | ImagePanel , name : str ) -> None :
8597 """Eventually takes plotwidget screenshot (only in screenshot mode)"""
8698 if execenv .screenshot :
Original file line number Diff line number Diff line change 99
1010import cdl .param
1111from cdl .obj import create_image
12- from cdl .tests import cdltest_app_context
12+ from cdl .tests import cdltest_app_context , skip_if_opencv_missing
1313from cdl .tests .data import get_test_image
1414
1515
@@ -32,7 +32,8 @@ def test_blobs():
3232 image = create_image (name , data )
3333 image .add_label_with_title ()
3434 panel .add_object (image )
35- compute_method (param )
35+ with skip_if_opencv_missing ():
36+ compute_method (param )
3637
3738 # Testing distribute_on_grid and reset_positions
3839 # ==============================================
Original file line number Diff line number Diff line change 1313import cdl .obj as dlo
1414import cdl .param as dlp
1515from cdl .proxy import proxy_context
16+ from cdl .tests import skip_if_opencv_missing
1617from cdl .tests .data import get_test_image
1718
1819
@@ -39,7 +40,8 @@ def test_example_app():
3940 filter_by_circularity = True ,
4041 min_circularity = 0.2 ,
4142 )
42- proxy .compute_blob_opencv (param )
43+ with skip_if_opencv_missing ():
44+ proxy .compute_blob_opencv (param )
4345
4446
4547if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments