Skip to content

Commit cdb947f

Browse files
maintainable tests mechanism added
1 parent 553c3d7 commit cdb947f

28 files changed

+596
-209
lines changed

.github/workflows/actions.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ jobs:
6363
pip install keras-nightly --progress-bar off
6464
- name: Test with pytest
6565
run: |
66-
if [ "${{ matrix.backend }}" == "openvino" ]; then
67-
IGNORE_FILE="openvino_excluded_tests.txt"
68-
IGNORE_ARGS=$(awk '{print "--ignore=" $0}' "$IGNORE_FILE")
69-
else
70-
IGNORE_ARGS=""
71-
fi
72-
pytest keras_hub/ $IGNORE_ARGS
66+
pytest keras_hub/
7367
- name: Run integration tests
7468
run: |
7569
python pip_build.py --install

conftest.py

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import keras
44
import 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

710
def 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

3444
def 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

7985
def 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.

integration_tests/basic_usage_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
import keras_hub
77

88

9-
@unittest.skipIf(
10-
keras.backend.backend() == "openvino",
11-
"Skip for non-trainable backends like OpenVINO",
12-
)
139
class BasicUsageTest(unittest.TestCase):
1410
def test_transformer(self):
1511
# Tokenize some inputs with a binary label.

keras_hub/src/layers/modeling/alibi_bias_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import keras
2-
import pytest
32
from keras import ops
43
from keras import random
54

@@ -8,7 +7,6 @@
87

98

109
class AlibiBiasTest(TestCase):
11-
@pytest.mark.requires_trainable_backend
1210
def test_layer_behaviors(self):
1311
alibi_bias_max = 8
1412
batch_size = 4

keras_hub/src/layers/modeling/anchor_generator_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
reason="Bbox utils are not supported before keras < 3.8.0",
1515
)
1616
class AnchorGeneratorTest(TestCase):
17-
@pytest.mark.requires_trainable_backend
1817
def test_layer_behaviors(self):
1918
images_shape = (8, 128, 128, 3)
2019
self.run_layer_test(

keras_hub/src/layers/modeling/cached_multi_head_attention_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from keras import ops
32
from keras import random
43

@@ -9,7 +8,6 @@
98

109

1110
class CachedMultiHeadAttentionTest(TestCase):
12-
@pytest.mark.requires_trainable_backend
1311
def test_layer_behaviors(self):
1412
self.run_layer_test(
1513
cls=CachedMultiHeadAttention,
@@ -77,7 +75,6 @@ def call(outputs, cache):
7775
self.assertAllClose(output, no_loop_outputs)
7876
self.assertAllClose(output_cache, no_loop_cache)
7977

80-
@pytest.mark.requires_trainable_backend
8178
def test_training_propagation(self):
8279
batch_size = 2
8380
seq_len = 5

keras_hub/src/layers/modeling/f_net_encoder_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from keras import ops
32
from keras import random
43

@@ -7,7 +6,6 @@
76

87

98
class FNetEncoderTest(TestCase):
10-
@pytest.mark.requires_trainable_backend
119
def test_layer_behaviors(self):
1210
self.run_layer_test(
1311
cls=FNetEncoder,
@@ -33,7 +31,6 @@ def test_value_error_when_invalid_kernel_initializer(self):
3331
kernel_initializer="Invalid",
3432
)
3533

36-
@pytest.mark.requires_trainable_backend
3734
def test_training_propagation(self):
3835
x = random.uniform(shape=(2, 4, 6))
3936
layer = FNetEncoder(

keras_hub/src/layers/modeling/masked_lm_head_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from keras import random
32

43
from keras_hub.src.layers.modeling.masked_lm_head import MaskedLMHead
@@ -9,7 +8,6 @@
98

109

1110
class MaskedLMHeadTest(TestCase):
12-
@pytest.mark.requires_trainable_backend
1311
def test_layer_behaviors(self):
1412
self.run_layer_test(
1513
cls=MaskedLMHead,
@@ -29,7 +27,6 @@ def test_layer_behaviors(self):
2927
expected_num_trainable_weights=6,
3028
)
3129

32-
@pytest.mark.requires_trainable_backend
3330
def test_layer_behaviors_with_embedding(self):
3431
embedding = ReversibleEmbedding(100, 16)
3532
embedding.build((4, 10))

keras_hub/src/layers/modeling/position_embedding_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import keras
22
import numpy as np
3-
import pytest
43
from keras import ops
54
from keras import random
65

@@ -16,7 +15,6 @@ def custom_init(shape, dtype=None):
1615

1716

1817
class PositionEmbeddingTest(TestCase):
19-
@pytest.mark.requires_trainable_backend
2018
def test_layer_behaviors(self):
2119
self.run_layer_test(
2220
cls=PositionEmbedding,
@@ -28,7 +26,6 @@ def test_layer_behaviors(self):
2826
expected_num_trainable_weights=1,
2927
)
3028

31-
@pytest.mark.requires_trainable_backend
3229
def test_layer_behaviors_4d(self):
3330
self.run_layer_test(
3431
cls=PositionEmbedding,

keras_hub/src/layers/modeling/reversible_embedding_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import keras
44
import numpy as np
5-
import pytest
65
from absl.testing import parameterized
76
from keras import ops
87
from keras import random
@@ -18,7 +17,6 @@ class ReversibleEmbeddingTest(TestCase):
1817
("tie_weights", True),
1918
("untie_weights", False),
2019
)
21-
@pytest.mark.requires_trainable_backend
2220
def test_layer_behaviors_tied(self, tie_weights):
2321
self.run_layer_test(
2422
cls=ReversibleEmbedding,

0 commit comments

Comments
 (0)