3
3
import keras
4
4
import pytest
5
5
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
+
6
9
7
10
def pytest_addoption (parser ):
8
11
parser .addoption (
@@ -29,6 +32,13 @@ def pytest_addoption(parser):
29
32
default = False ,
30
33
help = "fail if a gpu is not present" ,
31
34
)
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
+ )
32
42
33
43
34
44
def pytest_configure (config ):
@@ -70,16 +80,13 @@ def pytest_configure(config):
70
80
"markers" ,
71
81
"kaggle_key_required: mark test needing a kaggle key" ,
72
82
)
73
- config .addinivalue_line (
74
- "markers" ,
75
- "requires_trainable_backend: mark test for trainable backend only" ,
76
- )
77
83
78
84
79
85
def pytest_collection_modifyitems (config , items ):
80
86
run_extra_large_tests = config .getoption ("--run_extra_large" )
81
87
# Run large tests for --run_extra_large or --run_large.
82
88
run_large_tests = config .getoption ("--run_large" ) or run_extra_large_tests
89
+ auto_skip_training = config .getoption ("--auto_skip_training" )
83
90
84
91
# Messages to annotate skipped tests with.
85
92
skip_large = pytest .mark .skipif (
@@ -114,43 +121,23 @@ def pytest_collection_modifyitems(config, items):
114
121
if "kaggle_key_required" in item .keywords :
115
122
item .add_marker (kaggle_key_required )
116
123
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 :
141
138
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 } " )
146
140
)
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
- )
154
141
155
142
156
143
# Disable traceback filtering for quicker debugging of tests failures.
0 commit comments