|
15 | 15 | #
|
16 | 16 | import logging
|
17 | 17 | import os
|
18 |
| -import pickle |
19 | 18 | from collections import defaultdict
|
20 | 19 | from logging import FileHandler
|
21 | 20 |
|
|
25 | 24 | from _pytest.outcomes import OutcomeException
|
26 | 25 |
|
27 | 26 | from constants import MODEL_SERVICE, PREDICTION_SERVICE
|
28 |
| -from utils.helpers import get_xdist_worker_nr, get_xdist_worker_count |
29 |
| -from utils.xdist_utils import OvmsCLoadScheduling |
30 | 27 | from object_model.server import Server
|
| 28 | +from utils.other import reorder_items_by_fixtures_used |
31 | 29 | from utils.cleanup import clean_hanging_docker_resources, delete_test_directory, \
|
32 | 30 | get_containers_with_tests_suffix, get_docker_client
|
33 | 31 | from utils.logger import init_logger
|
34 | 32 | from tensorflow_serving.apis import prediction_service_pb2_grpc, \
|
35 | 33 | model_service_pb2_grpc # noqa
|
36 | 34 | from utils.files_operation import get_path_friendly_test_name
|
37 | 35 | from utils.parametrization import get_tests_suffix
|
38 |
| -from config import test_dir, test_dir_cleanup, artifacts_dir, using_xdist |
| 36 | +from config import test_dir, test_dir_cleanup, artifacts_dir |
39 | 37 |
|
40 | 38 | logger = logging.getLogger(__name__)
|
41 | 39 |
|
@@ -83,11 +81,6 @@ def pytest_configure():
|
83 | 81 | # Perform initial configuration.
|
84 | 82 | init_logger()
|
85 | 83 |
|
86 |
| - # if not os.environ.get("PYTEST_XDIST_WORKER", None): |
87 |
| - # copy_cached_models_to_test_dir() |
88 |
| - # copy_cached_resnet_models() |
89 |
| - |
90 |
| - |
91 | 84 | init_conf_logger = logging.getLogger("init_conf")
|
92 | 85 |
|
93 | 86 | container_names = get_containers_with_tests_suffix()
|
@@ -121,45 +114,7 @@ def pytest_unconfigure():
|
121 | 114 | @pytest.hookimpl(hookwrapper=True)
|
122 | 115 | def pytest_collection_modifyitems(session, config, items):
|
123 | 116 | yield
|
124 |
| - items = OvmsCLoadScheduling.reorder_items_by_fixtures_used(session) |
125 |
| - |
126 |
| - |
127 |
| -# |
128 |
| -# @pytest.hookimpl(hookwrapper=True) |
129 |
| -# def pytest_collection_finish(session): |
130 |
| -# yield |
131 |
| -# # Collect all fixtures that starts Docker instance |
132 |
| -# # This map will keep fixture usages in |
133 |
| -# |
134 |
| - |
135 |
| - |
136 |
| -# if not using_xdist: |
137 |
| -# @pytest.hookimpl(hookwrapper=True) |
138 |
| -# def pytest_runtestloop(session): |
139 |
| -# # Override default runtestloop in order to sort test execution by used fixtures |
140 |
| -# # This operation will ensure that only required containers will run and container will be cleared after all usages. |
141 |
| -# |
142 |
| -# # Collect all fixtures that starts Docker instance |
143 |
| -# # This map will keep fixture usages in tests |
144 |
| -# server_fixtures_to_item = defaultdict(lambda: []) |
145 |
| -# for item in session.items: |
146 |
| -# item._server_fixtures = list(filter(lambda x: "start_server_" in x, item.fixturenames)) |
147 |
| -# for fixture in item._server_fixtures: |
148 |
| -# server_fixtures_to_item[fixture].append(item) |
149 |
| -# |
150 |
| -# # Sort test items using required fixtures as key (group test by fixture) |
151 |
| -# sorted_items = sorted(session.items, key=lambda x: x._server_fixtures ) |
152 |
| -# |
153 |
| -# for i, item in enumerate(sorted_items): |
154 |
| -# nextitem = sorted_items[i + 1] if i + 1 < len(sorted_items) else None |
155 |
| -# item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) |
156 |
| -# |
157 |
| -# # Test finished: remove test item for all fixtures that was used |
158 |
| -# for fixture in item._server_fixtures: |
159 |
| -# server_fixtures_to_item[fixture].remove(item) |
160 |
| -# if len(server_fixtures_to_item[fixture]) == 0: |
161 |
| -# # No other tests will use this docker instance so we can close it. |
162 |
| -# Server.stop_by_fixture_name(fixture) |
| 117 | + items = reorder_items_by_fixtures_used(session) |
163 | 118 |
|
164 | 119 |
|
165 | 120 | @pytest.hookimpl(hookwrapper=True)
|
@@ -197,14 +152,13 @@ def pytest_runtest_teardown(item):
|
197 | 152 | yield
|
198 | 153 | # Test finished: remove test item for all fixtures that was used
|
199 | 154 | for fixture in item._server_fixtures:
|
200 |
| - if item in item.session._server_fixtures_to_item[fixture]: |
201 |
| - item.session._server_fixtures_to_item[fixture].remove(item) |
202 |
| - if len(item.session._server_fixtures_to_item[fixture]) == 0: |
| 155 | + if item in item.session._server_fixtures_to_tests[fixture]: |
| 156 | + item.session._server_fixtures_to_tests[fixture].remove(item) |
| 157 | + if len(item.session._server_fixtures_to_tests[fixture]) == 0: |
203 | 158 | # No other tests will use this docker instance so we can close it.
|
204 | 159 | Server.stop_by_fixture_name(fixture)
|
205 | 160 |
|
206 | 161 |
|
207 |
| - |
208 | 162 | def exception_catcher(when: str, outcome):
|
209 | 163 | if isinstance(outcome.excinfo, tuple):
|
210 | 164 | if len(outcome.excinfo) > 1 and isinstance(outcome.excinfo[1], OutcomeException):
|
@@ -241,8 +195,3 @@ def pytest_runtest_logfinish(nodeid, location):
|
241 | 195 | _root_logger.removeHandler(_root_logger._test_log_handler)
|
242 | 196 | yield
|
243 | 197 |
|
244 |
| - |
245 |
| -def pytest_xdist_make_scheduler(config, log): |
246 |
| - scheduler = OvmsCLoadScheduling(config, log) |
247 |
| - log.debug("Created xdist scheduler") |
248 |
| - return scheduler |
0 commit comments