|
1 | | -# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 1 | +# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | +import os |
| 4 | +import uuid |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 |
|
6 | 8 | def pytest_generate_tests(metafunc): |
7 | | - # If test expects param 'port' or 'flash_port', add parametrize |
| 9 | + allowed_ids = set() |
| 10 | + |
| 11 | + # get markers from test case (e.g. 'esp_box_3') |
| 12 | + for marker in metafunc.definition.iter_markers(): |
| 13 | + allowed_ids.add(marker.name) |
| 14 | + |
| 15 | + all_params = [ |
| 16 | + pytest.param('/dev/boards/esp-box-3', |
| 17 | + '/dev/boards/esp-box-3', |
| 18 | + 'build_esp-box-3', |
| 19 | + id='esp_box_3'), |
| 20 | + pytest.param('/dev/boards/esp32_c3_lcdkit', |
| 21 | + '/dev/boards/esp32_c3_lcdkit', |
| 22 | + 'build_esp32_c3_lcdkit', |
| 23 | + id='esp32_c3_lcdkit'), |
| 24 | + pytest.param('/dev/boards/esp32_p4_box', |
| 25 | + '/dev/boards/esp32_p4_box', |
| 26 | + 'build_esp32_p4_box', |
| 27 | + id='esp32_p4_box'), |
| 28 | + pytest.param('/dev/boards/esp32_p4_function_ev_board', |
| 29 | + '/dev/boards/esp32_p4_function_ev_board', |
| 30 | + 'build_esp32_p4_function_ev_board', |
| 31 | + id='esp32_p4_function_ev_board'), |
| 32 | + pytest.param('/dev/boards/esp32_s3_eye', |
| 33 | + '/dev/boards/esp32_s3_eye', |
| 34 | + 'build_esp32_s3_eye', |
| 35 | + id='esp32_s3_eye'), |
| 36 | + pytest.param('/dev/boards/esp32_s3_lcd_ev_board', |
| 37 | + '/dev/boards/esp32_s3_lcd_ev_board', |
| 38 | + 'build_esp32_s3_lcd_ev_board', |
| 39 | + id='esp32_s3_lcd_ev_board'), |
| 40 | + pytest.param('/dev/boards/esp32_s3_lcd_ev_board-2', |
| 41 | + '/dev/boards/esp32_s3_lcd_ev_board-2', |
| 42 | + 'build_esp32_s3_lcd_ev_board', |
| 43 | + id='esp32_s3_lcd_ev_board_2'), |
| 44 | + pytest.param('/dev/boards/esp32_s3_usb_otg', |
| 45 | + '/dev/boards/esp32_s3_usb_otg', |
| 46 | + 'build_esp32_s3_usb_otg', |
| 47 | + id='esp32_s3_usb_otg'), |
| 48 | + pytest.param('/dev/boards/esp_wrover_kit', |
| 49 | + '/dev/boards/esp_wrover_kit', |
| 50 | + 'build_esp_wrover_kit', |
| 51 | + id='esp_wrover_kit'), |
| 52 | + pytest.param('/dev/boards/esp32_azure_iot_kit', |
| 53 | + '/dev/boards/esp32_azure_iot_kit', |
| 54 | + 'build_esp32_azure_iot_kit', |
| 55 | + id='esp32_azure_iot_kit'), |
| 56 | + pytest.param('/dev/boards/m5dial', |
| 57 | + '/dev/boards/m5dial', |
| 58 | + 'build_m5dial', |
| 59 | + id='m5dial'), |
| 60 | + pytest.param('/dev/boards/m5stack_core', |
| 61 | + '/dev/boards/m5stack_core', |
| 62 | + 'build_m5stack_core', |
| 63 | + id='m5stack_core'), |
| 64 | + pytest.param('/dev/boards/m5stack_core_2', |
| 65 | + '/dev/boards/m5stack_core_2', |
| 66 | + 'build_m5stack_core', |
| 67 | + id='m5stack_core_2'), |
| 68 | + pytest.param('/dev/boards/m5stack_core_s3', |
| 69 | + '/dev/boards/m5stack_core_s3', |
| 70 | + 'build_m5stack_core_s3', |
| 71 | + id='m5stack_core_s3'), |
| 72 | + pytest.param('/dev/boards/m5stack_core_s3_se', |
| 73 | + '/dev/boards/m5stack_core_s3_se', |
| 74 | + 'build_m5stack_core_s3', |
| 75 | + id='m5stack_core_s3_se'), |
| 76 | + pytest.param('/dev/boards/m5_atom_s3', |
| 77 | + '/dev/boards/m5_atom_s3', |
| 78 | + 'build_m5_atom_s3', |
| 79 | + id='m5_atom_s3'), |
| 80 | + pytest.param('/dev/boards/esp32_s3_devkitc_1_1', |
| 81 | + '/dev/boards/esp32_s3_devkitc_1_1', |
| 82 | + 'build_esp_bsp_devkit', |
| 83 | + id='esp_bsp_devkit'), |
| 84 | + pytest.param('/dev/boards/esp32_s2_devkitc_1', |
| 85 | + '/dev/boards/esp32_s2_devkitc_1', |
| 86 | + 'build_esp_bsp_generic', |
| 87 | + id='esp_bsp_generic'), |
| 88 | + pytest.param('/dev/boards/esp32_s3_korvo_2', |
| 89 | + '/dev/boards/esp32_s3_korvo_2', |
| 90 | + 'build_esp32_s3_korvo_2', |
| 91 | + id='esp32_s3_korvo_2'), |
| 92 | + ] |
| 93 | + |
| 94 | + # filter by markers |
| 95 | + selected_params = [ |
| 96 | + p for p in all_params if p.id in allowed_ids |
| 97 | + ] |
| 98 | + |
| 99 | + # if not markers, use all |
| 100 | + if not selected_params: |
| 101 | + selected_params = all_params |
| 102 | + |
8 | 103 | if 'port' in metafunc.fixturenames and 'flash_port' in metafunc.fixturenames: |
9 | 104 | metafunc.parametrize( |
10 | | - 'port, flash_port', |
11 | | - [ |
12 | | - pytest.param('/dev/boards/esp-box-3', '/dev/boards/esp-box-3', id='esp_box_3'), |
13 | | - pytest.param('/dev/boards/esp32_c3_lcdkit', '/dev/boards/esp32_c3_lcdkit', id='esp32_c3_lcdkit'), |
14 | | - pytest.param('/dev/boards/esp32_p4_box', '/dev/boards/esp32_p4_box', id='esp32_p4_box'), |
15 | | - pytest.param('/dev/boards/esp32_p4_function_ev_board', '/dev/boards/esp32_p4_function_ev_board', id='esp32_p4_function_ev_board'), |
16 | | - pytest.param('/dev/boards/esp32_s3_eye', '/dev/boards/esp32_s3_eye', id='esp32_s3_eye'), |
17 | | - pytest.param('/dev/boards/esp32_s3_lcd_ev_board', '/dev/boards/esp32_s3_lcd_ev_board', id='esp32_s3_lcd_ev_board'), |
18 | | - pytest.param('/dev/boards/esp32_s3_lcd_ev_board-2', '/dev/boards/esp32_s3_lcd_ev_board-2', id='esp32_s3_lcd_ev_board_2'), |
19 | | - pytest.param('/dev/boards/esp32_s3_usb_otg', '/dev/boards/esp32_s3_usb_otg', id='esp32_s3_usb_otg'), |
20 | | - pytest.param('/dev/boards/esp_wrover_kit', '/dev/boards/esp_wrover_kit', id='esp_wrover_kit'), |
21 | | - pytest.param('/dev/boards/esp32_azure_iot_kit', '/dev/boards/esp32_azure_iot_kit', id='esp32_azure_iot_kit'), |
22 | | - pytest.param('/dev/boards/m5dial', '/dev/boards/m5dial', id='m5dial'), |
23 | | - pytest.param('/dev/boards/m5stack_core', '/dev/boards/m5stack_core', id='m5stack_core'), |
24 | | - pytest.param('/dev/boards/m5stack_core_2', '/dev/boards/m5stack_core_2', id='m5stack_core_2'), |
25 | | - pytest.param('/dev/boards/m5stack_core_s3', '/dev/boards/m5stack_core_s3', id='m5stack_core_s3'), |
26 | | - pytest.param('/dev/boards/m5stack_core_s3_se', '/dev/boards/m5stack_core_s3_se', id='m5stack_core_s3_se'), |
27 | | - pytest.param('/dev/boards/m5_atom_s3', '/dev/boards/m5_atom_s3', id='m5_atom_s3'), |
28 | | - pytest.param('/dev/boards/esp32_s3_devkitc_1_1', '/dev/boards/esp32_s3_devkitc_1_1', id='esp_bsp_devkit'), |
29 | | - pytest.param('/dev/boards/esp32_s3_devkitc_1_1', '/dev/boards/esp32_s3_devkitc_1_1', id='esp_bsp_generic'), |
30 | | - pytest.param('/dev/boards/esp32_s3_korvo_2', '/dev/boards/esp32_s3_korvo_2', id='esp32_s3_korvo_2'), |
31 | | - ] |
| 105 | + 'port, flash_port, build_dir', |
| 106 | + selected_params |
32 | 107 | ) |
33 | 108 |
|
34 | 109 |
|
35 | | -# Check marker with params and test ID |
36 | | -def pytest_collection_modifyitems(config, items): |
37 | | - for item in items: |
38 | | - marker_option = "[" + config.getoption("-m") + "]" |
39 | | - if marker_option not in item.nodeid: |
40 | | - item.add_marker(pytest.mark.skip(reason="Not for selected params")) |
| 110 | +@pytest.fixture |
| 111 | +def build_dir(build_dir: str) -> str: |
| 112 | + return f'{build_dir}' |
| 113 | + |
| 114 | + |
| 115 | +# This fixing using cache when used "-n auto" (parallel) |
| 116 | +def pytest_configure(config): |
| 117 | + # If run pytest-xdist (parallel), set unique cache dir |
| 118 | + worker_id = os.getenv("PYTEST_XDIST_WORKER", None) |
| 119 | + if worker_id: |
| 120 | + cache_dir = f"/tmp/pytest-embedded-cache-{uuid.uuid4()}" |
| 121 | + os.environ["PYTEST_EMBEDDED_CACHE_DIR"] = cache_dir |
| 122 | + os.makedirs(cache_dir, exist_ok=True) |
| 123 | + print(f"Using embedded cache dir: {cache_dir}") |
0 commit comments