|
12 | 12 | # limitations under the License |
13 | 13 |
|
14 | 14 | """This package contains integration tests for the project.""" |
| 15 | +from collections import defaultdict |
| 16 | +from typing import Optional |
| 17 | + |
| 18 | +from reportportal_client import set_current |
| 19 | +from reportportal_client.steps import StepReporter |
15 | 20 |
|
16 | 21 | from tests.helpers import utils |
17 | 22 |
|
|
272 | 277 | (test, HIERARCHY_TEST_VARIABLES[idx], HIERARCHY_TEST_EXPECTED_ITEMS[idx]) |
273 | 278 | for idx, test in enumerate(HIERARCHY_TESTS) |
274 | 279 | ] |
| 280 | + |
| 281 | +ITEM_ID_DICT = defaultdict(lambda: 0) |
| 282 | +ITEM_ID_LIST = [] |
| 283 | + |
| 284 | + |
| 285 | +def generate_item_id(*args, **kwargs) -> str: |
| 286 | + global ITEM_ID_DICT |
| 287 | + global ITEM_ID_LIST |
| 288 | + if args: |
| 289 | + name = args[0] |
| 290 | + else: |
| 291 | + name = kwargs["name"] |
| 292 | + count = ITEM_ID_DICT[name] |
| 293 | + count += 1 |
| 294 | + ITEM_ID_DICT[name] = count |
| 295 | + item_id = f"{name}_{count}" |
| 296 | + ITEM_ID_LIST.append(item_id) |
| 297 | + return item_id |
| 298 | + |
| 299 | + |
| 300 | +def get_last_item_id() -> Optional[str]: |
| 301 | + global ITEM_ID_LIST |
| 302 | + if len(ITEM_ID_LIST) > 0: |
| 303 | + return ITEM_ID_LIST[-1] |
| 304 | + |
| 305 | + |
| 306 | +def remove_last_item_id(*_, **__) -> Optional[str]: |
| 307 | + global ITEM_ID_LIST |
| 308 | + if len(ITEM_ID_LIST) > 0: |
| 309 | + return ITEM_ID_LIST.pop() |
| 310 | + |
| 311 | + |
| 312 | +def setup_mock(mock_client_init): |
| 313 | + mock_client = mock_client_init.return_value |
| 314 | + mock_client.step_reporter = StepReporter(mock_client) |
| 315 | + set_current(mock_client) |
| 316 | + return mock_client |
| 317 | + |
| 318 | + |
| 319 | +def setup_mock_for_logging(mock_client_init): |
| 320 | + mock_client = setup_mock(mock_client_init) |
| 321 | + mock_client.start_test_item.side_effect = generate_item_id |
| 322 | + mock_client.finish_test_item.side_effect = remove_last_item_id |
| 323 | + mock_client.current_item.side_effect = get_last_item_id |
| 324 | + return mock_client |
0 commit comments