33import keras
44import pytest
55
6+ from keras_hub .src .utils .openvino_utils import get_openvino_skip_reason
7+ from keras_hub .src .utils .openvino_utils import setup_openvino_test_config
8+
69
710def pytest_addoption (parser ):
811 parser .addoption (
@@ -29,6 +32,13 @@ def pytest_addoption(parser):
2932 default = False ,
3033 help = "fail if a gpu is not present" ,
3134 )
35+ parser .addoption (
36+ "--auto_skip_training" ,
37+ action = "store_true" ,
38+ default = True ,
39+ help = "automatically skip tests with "
40+ "training methods on non-trainable backends" ,
41+ )
3242
3343
3444def pytest_configure (config ):
@@ -70,16 +80,13 @@ def pytest_configure(config):
7080 "markers" ,
7181 "kaggle_key_required: mark test needing a kaggle key" ,
7282 )
73- config .addinivalue_line (
74- "markers" ,
75- "requires_trainable_backend: mark test for trainable backend only" ,
76- )
7783
7884
7985def pytest_collection_modifyitems (config , items ):
8086 run_extra_large_tests = config .getoption ("--run_extra_large" )
8187 # Run large tests for --run_extra_large or --run_large.
8288 run_large_tests = config .getoption ("--run_large" ) or run_extra_large_tests
89+ auto_skip_training = config .getoption ("--auto_skip_training" )
8390
8491 # Messages to annotate skipped tests with.
8592 skip_large = pytest .mark .skipif (
@@ -114,43 +121,23 @@ def pytest_collection_modifyitems(config, items):
114121 if "kaggle_key_required" in item .keywords :
115122 item .add_marker (kaggle_key_required )
116123
117- openvino_skipped_tests = []
118- if keras .config .backend () == "openvino" :
119- from pathlib import Path
120-
121- workspace_root = Path (__file__ ).resolve ().parents [0 ]
122- file_path = workspace_root / "openvino_excluded_concrete_tests.txt"
123- with open (file_path , "r" ) as file :
124- openvino_skipped_tests = [
125- line .strip () for line in file if line .strip ()
126- ]
127-
128- requires_trainable_backend = pytest .mark .skipif (
129- keras .config .backend () in ["openvino" ],
130- reason = "fit not implemented for OpenVINO backend." ,
131- )
132-
133- for item in items :
134- if "requires_trainable_backend" in item .keywords :
135- item .add_marker (requires_trainable_backend )
136- # also, skip concrete tests for openvino, listed in the special file
137- # this is more granular mechanism to exclude tests rather
138- # than using --ignore option
139- for skipped_test in openvino_skipped_tests :
140- if skipped_test in item .nodeid :
124+ # OpenVINO-specific skipping logic - whitelist-based approach
125+ if keras .config .backend () == "openvino" :
126+ # OpenVINO backend configuration
127+ from pathlib import Path
128+
129+ openvino_supported_paths = setup_openvino_test_config (
130+ str (Path (__file__ ).parent )
131+ )
132+ skip_reason = get_openvino_skip_reason (
133+ item ,
134+ openvino_supported_paths ,
135+ auto_skip_training ,
136+ )
137+ if skip_reason :
141138 item .add_marker (
142- skip_if_backend (
143- "openvino" ,
144- "Not supported operation by openvino backend" ,
145- )
139+ pytest .mark .skipif (True , reason = f"OpenVINO: { skip_reason } " )
146140 )
147- break
148-
149-
150- def skip_if_backend (given_backend , reason ):
151- return pytest .mark .skipif (
152- keras .config .backend () == given_backend , reason = reason
153- )
154141
155142
156143# Disable traceback filtering for quicker debugging of tests failures.
0 commit comments