|
2 | 2 |
|
3 | 3 | import keras |
4 | 4 | import pytest |
| 5 | +from keras.src.backend import backend |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def pytest_addoption(parser): |
@@ -70,6 +71,10 @@ def pytest_configure(config): |
70 | 71 | "markers", |
71 | 72 | "kaggle_key_required: mark test needing a kaggle key", |
72 | 73 | ) |
| 74 | + config.addinivalue_line( |
| 75 | + "markers", |
| 76 | + "requires_trainable_backend: mark test for trainable backend only", |
| 77 | + ) |
73 | 78 |
|
74 | 79 |
|
75 | 80 | def pytest_collection_modifyitems(config, items): |
@@ -110,6 +115,42 @@ def pytest_collection_modifyitems(config, items): |
110 | 115 | if "kaggle_key_required" in item.keywords: |
111 | 116 | item.add_marker(kaggle_key_required) |
112 | 117 |
|
| 118 | + openvino_skipped_tests = [] |
| 119 | + if backend() == "openvino": |
| 120 | + from pathlib import Path |
| 121 | + |
| 122 | + workspace_root = Path(__file__).resolve().parents[0] |
| 123 | + file_path = workspace_root / "openvino_excluded_concrete_tests.txt" |
| 124 | + with open(file_path, "r") as file: |
| 125 | + openvino_skipped_tests = [ |
| 126 | + line.strip() for line in file if line.strip() |
| 127 | + ] |
| 128 | + |
| 129 | + requires_trainable_backend = pytest.mark.skipif( |
| 130 | + backend() in ["openvino"], |
| 131 | + reason="Trainer not implemented for OpenVINO backend.", |
| 132 | + ) |
| 133 | + |
| 134 | + for item in items: |
| 135 | + if "requires_trainable_backend" in item.keywords: |
| 136 | + item.add_marker(requires_trainable_backend) |
| 137 | + # also, skip concrete tests for openvino, listed in the special file |
| 138 | + # this is more granular mechanism to exclude tests rather |
| 139 | + # than using --ignore option |
| 140 | + for skipped_test in openvino_skipped_tests: |
| 141 | + if skipped_test in item.nodeid: |
| 142 | + item.add_marker( |
| 143 | + skip_if_backend( |
| 144 | + "openvino", |
| 145 | + "Not supported operation by openvino backend", |
| 146 | + ) |
| 147 | + ) |
| 148 | + break |
| 149 | + |
| 150 | + |
| 151 | +def skip_if_backend(given_backend, reason): |
| 152 | + return pytest.mark.skipif(backend() == given_backend, reason=reason) |
| 153 | + |
113 | 154 |
|
114 | 155 | # Disable traceback filtering for quicker debugging of tests failures. |
115 | 156 | keras.config.disable_traceback_filtering() |
0 commit comments