1
1
import os
2
- from pathlib import Path
3
2
4
3
import keras
5
4
import pytest
6
5
7
- from keras_hub .src .utils .openvino_utils import get_openvino_skip_reason
8
- from keras_hub .src .utils .openvino_utils import setup_openvino_test_config
9
-
10
6
11
7
def pytest_addoption (parser ):
12
8
parser .addoption (
@@ -33,16 +29,27 @@ def pytest_addoption(parser):
33
29
default = False ,
34
30
help = "fail if a gpu is not present" ,
35
31
)
36
- parser .addoption (
37
- "--auto_skip_training" ,
38
- action = "store_true" ,
39
- default = True ,
40
- help = "automatically skip tests with "
41
- "training methods on non-trainable backends" ,
42
- )
43
32
44
33
45
34
def pytest_configure (config ):
35
+ # Monkey-patch training methods for OpenVINO backend
36
+ if keras .config .backend () == "openvino" :
37
+ # Store original methods in case we need to restore them
38
+ if not hasattr (keras .Model , "_original_compile" ):
39
+ keras .Model ._original_compile = keras .Model .compile
40
+ keras .Model ._original_fit = keras .Model .fit
41
+ keras .Model ._original_train_on_batch = keras .Model .train_on_batch
42
+
43
+ keras .Model .compile = lambda * args , ** kwargs : pytest .skip (
44
+ "Model.compile() not supported on OpenVINO backend"
45
+ )
46
+ keras .Model .fit = lambda * args , ** kwargs : pytest .skip (
47
+ "Model.fit() not supported on OpenVINO backend"
48
+ )
49
+ keras .Model .train_on_batch = lambda * args , ** kwargs : pytest .skip (
50
+ "Model.train_on_batch() not supported on OpenVINO backend"
51
+ )
52
+
46
53
# Verify that device has GPU and detected by backend
47
54
if config .getoption ("--check_gpu" ):
48
55
found_gpu = False
@@ -84,12 +91,9 @@ def pytest_configure(config):
84
91
85
92
86
93
def pytest_collection_modifyitems (config , items ):
87
- openvino_supported_paths = None
88
-
89
94
run_extra_large_tests = config .getoption ("--run_extra_large" )
90
95
# Run large tests for --run_extra_large or --run_large.
91
96
run_large_tests = config .getoption ("--run_large" ) or run_extra_large_tests
92
- auto_skip_training = config .getoption ("--auto_skip_training" )
93
97
94
98
# Messages to annotate skipped tests with.
95
99
skip_large = pytest .mark .skipif (
@@ -124,21 +128,58 @@ def pytest_collection_modifyitems(config, items):
124
128
if "kaggle_key_required" in item .keywords :
125
129
item .add_marker (kaggle_key_required )
126
130
127
- # OpenVINO-specific skipping logic - whitelist-based approach
131
+ # OpenVINO-specific test skipping
128
132
if keras .config .backend () == "openvino" :
129
- # OpenVINO backend configuration
130
- if openvino_supported_paths is None :
131
- openvino_supported_paths = setup_openvino_test_config (
132
- str (Path (__file__ ).parent )
133
+ test_name = item .name .split ("[" )[0 ]
134
+ test_path = str (item .fspath )
135
+
136
+ # OpenVINO supported test paths
137
+ openvino_supported_paths = [
138
+ "keras-hub/integration_tests" ,
139
+ "keras_hub/src/models/gemma" ,
140
+ "keras_hub/src/models/gpt2" ,
141
+ "keras_hub/src/models/mistral" ,
142
+ "keras_hub/src/samplers/serialization_test.py" ,
143
+ "keras_hub/src/tests/doc_tests/docstring_test.py" ,
144
+ "keras_hub/src/tokenizers" ,
145
+ "keras_hub/src/utils" ,
146
+ ]
147
+
148
+ # Skip specific problematic test methods
149
+ specific_skipping_tests = {
150
+ "test_backbone_basics" : "Requires trainable backend" ,
151
+ "test_score_loss" : "Non-implemented roll operation" ,
152
+ "test_layer_behaviors" : "Requires trainable backend" ,
153
+ }
154
+
155
+ if test_name in specific_skipping_tests :
156
+ item .add_marker (
157
+ pytest .mark .skipif (
158
+ True ,
159
+ reason = "OpenVINO: "
160
+ f"{ specific_skipping_tests [test_name ]} " ,
161
+ )
133
162
)
134
- skip_reason = get_openvino_skip_reason (
135
- item ,
136
- openvino_supported_paths ,
137
- auto_skip_training ,
163
+ continue
164
+
165
+ parts = test_path .replace ("\\ " , "/" ).split ("/" )
166
+ try :
167
+ keras_hub_idx = parts .index ("keras_hub" )
168
+ relative_test_path = "/" .join (parts [keras_hub_idx :])
169
+ except ValueError :
170
+ relative_test_path = test_path
171
+
172
+ is_whitelisted = any (
173
+ relative_test_path == supported_path
174
+ or relative_test_path .startswith (supported_path + "/" )
175
+ for supported_path in openvino_supported_paths
138
176
)
139
- if skip_reason :
177
+
178
+ if not is_whitelisted :
140
179
item .add_marker (
141
- pytest .mark .skipif (True , reason = f"OpenVINO: { skip_reason } " )
180
+ pytest .mark .skipif (
181
+ True , reason = "OpenVINO: File/directory not in whitelist"
182
+ )
142
183
)
143
184
144
185
0 commit comments