From 8691672f03b12075df43abf8ed578ee67e4fb96a Mon Sep 17 00:00:00 2001 From: "igor.udot" Date: Mon, 6 May 2024 11:12:04 +0800 Subject: [PATCH] ci: replace pytest function --- .../test_apps/pytest_app_update_ut.py | 11 +----- .../test_apps/general/pytest_cxx_general.py | 11 ++---- .../pytest_legacy_temp_sensor_driver.py | 7 +--- .../test_apps/pytest_esp_bootloader_format.py | 1 - .../test_apps/rtc_clk/pytest_rtc_clk.py | 14 ++----- .../pytest_esp_vfs_l2tap.py | 8 +--- .../test_apps/hal_utils/pytest_hal_utils.py | 3 +- .../heap/test_apps/heap_tests/pytest_heap.py | 38 +++++-------------- components/lwip/test_apps/pytest_lwip.py | 1 - .../nvs_flash/test_apps/pytest_nvs_flash.py | 6 +-- .../pytest_pthread_unity_tests.py | 11 ++---- components/spiffs/test_apps/pytest_spiffs.py | 15 ++------ .../test_apps/pytest_tcp_transport_ut.py | 1 - .../test_apps/pytest_touch_element.py | 4 +- .../test_apps/pytest_wear_levelling.py | 1 - .../contribute/esp-idf-tests-with-pytest.rst | 30 +++++++++++---- .../contribute/esp-idf-tests-with-pytest.rst | 30 +++++++++++---- 17 files changed, 79 insertions(+), 113 deletions(-) diff --git a/components/app_update/test_apps/pytest_app_update_ut.py b/components/app_update/test_apps/pytest_app_update_ut.py index bd5902cb4f..9734d6e7c8 100644 --- a/components/app_update/test_apps/pytest_app_update_ut.py +++ b/components/app_update/test_apps/pytest_app_update_ut.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 import re @@ -22,11 +22,4 @@ def run_multiple_stages(dut: Dut, test_case_num: int, stages: int) -> None: @pytest.mark.temp_skip_ci(targets=['esp32c5'], reason='C5 has not supported deep sleep') # TODO: [ESP32C5] IDF-8640, IDF-10317 @pytest.mark.generic def test_app_update(dut: Dut) -> None: - extra_data = dut.parse_test_menu() - for test_case in extra_data: - if test_case.type != 'multi_stage': - dut.write(str(test_case.index)) - else: - run_multiple_stages(dut, test_case.index, len(test_case.subcases)) - dut.expect_unity_test_output(timeout=90) - dut.expect_exact("Enter next test, or 'enter' to see menu") + dut.run_all_single_board_cases(timeout=90) diff --git a/components/cxx/test_apps/general/pytest_cxx_general.py b/components/cxx/test_apps/general/pytest_cxx_general.py index 166eb5af5e..0ba975526b 100644 --- a/components/cxx/test_apps/general/pytest_cxx_general.py +++ b/components/cxx/test_apps/general/pytest_cxx_general.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut @@ -15,9 +14,7 @@ configurations = [ @pytest.mark.generic @pytest.mark.parametrize('config', configurations, indirect=True) def test_cxx_static_init_non_pod(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('\"can use static initializers for non-POD types\"') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(name=['can use static initializers for non-POD types']) @pytest.mark.esp32 @@ -25,9 +22,7 @@ def test_cxx_static_init_non_pod(dut: Dut) -> None: @pytest.mark.generic @pytest.mark.parametrize('config', configurations, indirect=True) def test_cxx_misc(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[misc]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(group='misc') @pytest.mark.esp32 diff --git a/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py b/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py index cfa870a30a..cf77604bda 100644 --- a/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py +++ b/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut @@ -17,6 +16,4 @@ from pytest_embedded import Dut 'release', ], indirect=True) def test_legacy_temp_sensor_driver(dut: Dut) -> None: - dut.expect('Press ENTER to see the list of tests') - dut.write('*') - dut.expect_unity_test_output(timeout=120) + dut.run_all_single_board_cases(timeout=120) diff --git a/components/esp_bootloader_format/test_apps/pytest_esp_bootloader_format.py b/components/esp_bootloader_format/test_apps/pytest_esp_bootloader_format.py index 76879159c7..fa4d7a7f3a 100644 --- a/components/esp_bootloader_format/test_apps/pytest_esp_bootloader_format.py +++ b/components/esp_bootloader_format/test_apps/pytest_esp_bootloader_format.py @@ -1,6 +1,5 @@ # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut diff --git a/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py b/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py index 384dd05fe3..cd5d5fc82b 100644 --- a/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py +++ b/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 from typing import Any @@ -9,25 +9,19 @@ from pytest_embedded import Dut @pytest.mark.generic @pytest.mark.esp32 def test_rtc_clk(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[rtc_clk]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(group='rtc_clk') @pytest.mark.esp32 @pytest.mark.xtal32k def test_rtc_xtal32k(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[test_env=xtal32k]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(attributes={'test_env': 'xtal32k'}) @pytest.mark.esp32 @pytest.mark.no32kXtal def test_rtc_no_xtal32k(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[test_env=noXtal32k]') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(attributes={'test_env': 'noXtal32k'}) @pytest.mark.generic diff --git a/components/esp_netif/test_apps/test_app_vfs_l2tap/pytest_esp_vfs_l2tap.py b/components/esp_netif/test_apps/test_app_vfs_l2tap/pytest_esp_vfs_l2tap.py index 972bee544b..966483b517 100644 --- a/components/esp_netif/test_apps/test_app_vfs_l2tap/pytest_esp_vfs_l2tap.py +++ b/components/esp_netif/test_apps/test_app_vfs_l2tap/pytest_esp_vfs_l2tap.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest from pytest_embedded import Dut @@ -7,8 +7,4 @@ from pytest_embedded import Dut @pytest.mark.esp32 @pytest.mark.ethernet def test_esp_netif_vfs_l2tp(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('\n') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output() + dut.run_all_single_board_cases() diff --git a/components/hal/test_apps/hal_utils/pytest_hal_utils.py b/components/hal/test_apps/hal_utils/pytest_hal_utils.py index ceb3c30e88..665355ba89 100644 --- a/components/hal/test_apps/hal_utils/pytest_hal_utils.py +++ b/components/hal/test_apps/hal_utils/pytest_hal_utils.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import pytest from pytest_embedded import Dut diff --git a/components/heap/test_apps/heap_tests/pytest_heap.py b/components/heap/test_apps/heap_tests/pytest_heap.py index 4bed368aba..ab420f6114 100644 --- a/components/heap/test_apps/heap_tests/pytest_heap.py +++ b/components/heap/test_apps/heap_tests/pytest_heap.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut @@ -74,13 +73,10 @@ def test_heap(dut: Dut) -> None: ] ) def test_heap_misc_options(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('"IRAM_8BIT capability test"') - dut.expect_unity_test_output() - - dut.expect_exact("Enter next test, or 'enter' to see menu") - dut.write('"test allocation and free function hooks"') - dut.expect_unity_test_output() + dut.run_all_single_board_cases(name=[ + 'IRAM_8BIT capability test', + 'test allocation and free function hooks' + ]) dut.expect_exact("Enter next test, or 'enter' to see menu") dut.write('"When enabled, allocation operation failure generates an abort"') @@ -97,22 +93,10 @@ def test_heap_misc_options(dut: Dut) -> None: ] ) def test_heap_trace_dump(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[trace-dump][internal]') - dut.expect('Internal') - - dut.expect_exact('Enter next test, or \'enter\' to see menu') - dut.write('[trace-dump][external]') - dut.expect('PSRAM') - - dut.expect_exact('Enter next test, or \'enter\' to see menu') - dut.write('[trace-dump][all]') - dut.expect('Internal') - dut.expect('PSRAM') - - dut.expect_exact('Enter next test, or \'enter\' to see menu') - dut.write('[heap-trace]') - dut.expect_unity_test_output(timeout=100) + dut.run_all_single_board_cases(group='trace-dump&internal') + dut.run_all_single_board_cases(group='trace-dump&external') + dut.run_all_single_board_cases(group='trace-dump&all') + dut.run_all_single_board_cases(group='heap-trace') @pytest.mark.generic @@ -124,6 +108,4 @@ def test_heap_trace_dump(dut: Dut) -> None: ] ) def test_memory_protection(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('[heap][mem_prot]') - dut.expect_unity_test_output(timeout=300) + dut.run_all_single_board_cases(group='heap&mem_prot', timeout=300) diff --git a/components/lwip/test_apps/pytest_lwip.py b/components/lwip/test_apps/pytest_lwip.py index 32de3ef610..02b4bc2ee8 100644 --- a/components/lwip/test_apps/pytest_lwip.py +++ b/components/lwip/test_apps/pytest_lwip.py @@ -1,6 +1,5 @@ # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import pytest from pytest_embedded import Dut diff --git a/components/nvs_flash/test_apps/pytest_nvs_flash.py b/components/nvs_flash/test_apps/pytest_nvs_flash.py index 81d3a6caa5..76d1ce59a9 100644 --- a/components/nvs_flash/test_apps/pytest_nvs_flash.py +++ b/components/nvs_flash/test_apps/pytest_nvs_flash.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import pytest from pytest_embedded_idf.dut import IdfDut @@ -13,9 +13,7 @@ CONFIGS_NVS_ENCR_FLASH_ENC = [ @pytest.mark.esp32c3 @pytest.mark.parametrize('config', ['default'], indirect=True) def test_nvs_flash(dut: IdfDut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('![nvs_encr_hmac]') - dut.expect_unity_test_output(timeout=120) + dut.run_all_single_board_cases(group='!nvs_encr_hmac', timeout=120) @pytest.mark.esp32c3 diff --git a/components/pthread/test_apps/pthread_unity_tests/pytest_pthread_unity_tests.py b/components/pthread/test_apps/pthread_unity_tests/pytest_pthread_unity_tests.py index 1ee39baa72..a2a231214e 100644 --- a/components/pthread/test_apps/pthread_unity_tests/pytest_pthread_unity_tests.py +++ b/components/pthread/test_apps/pthread_unity_tests/pytest_pthread_unity_tests.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut @@ -15,9 +14,7 @@ from pytest_embedded import Dut indirect=True, ) def test_pthread(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('![thread-specific]') - dut.expect_unity_test_output(timeout=300) + dut.run_all_single_board_cases(group='!thread-specific', timeout=300) @pytest.mark.generic @@ -30,9 +27,7 @@ def test_pthread(dut: Dut) -> None: indirect=True, ) def test_pthread_single_core(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('![thread-specific]') - dut.expect_unity_test_output(timeout=300) + dut.run_all_single_board_cases(group='!thread-specific', timeout=300) @pytest.mark.generic diff --git a/components/spiffs/test_apps/pytest_spiffs.py b/components/spiffs/test_apps/pytest_spiffs.py index 33e5253937..ef4a26fe16 100644 --- a/components/spiffs/test_apps/pytest_spiffs.py +++ b/components/spiffs/test_apps/pytest_spiffs.py @@ -1,6 +1,5 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut @@ -13,11 +12,7 @@ from pytest_embedded import Dut 'release', ], indirect=True) def test_spiffs_generic(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) + dut.run_all_single_board_cases(timeout=120) @pytest.mark.esp32s3 @@ -26,8 +21,4 @@ def test_spiffs_generic(dut: Dut) -> None: 'psram', ], indirect=True) def test_spiffs_psram(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) + dut.run_all_single_board_cases(timeout=120) diff --git a/components/tcp_transport/test_apps/pytest_tcp_transport_ut.py b/components/tcp_transport/test_apps/pytest_tcp_transport_ut.py index c05984182d..e61f61788b 100644 --- a/components/tcp_transport/test_apps/pytest_tcp_transport_ut.py +++ b/components/tcp_transport/test_apps/pytest_tcp_transport_ut.py @@ -1,6 +1,5 @@ # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut diff --git a/components/touch_element/test_apps/pytest_touch_element.py b/components/touch_element/test_apps/pytest_touch_element.py index e5651438df..75b07625be 100644 --- a/components/touch_element/test_apps/pytest_touch_element.py +++ b/components/touch_element/test_apps/pytest_touch_element.py @@ -16,6 +16,4 @@ from pytest_embedded import Dut indirect=True, ) def test_touch_element(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('*') - dut.expect_unity_test_output(timeout=120) + dut.run_all_single_board_cases(timeout=120) diff --git a/components/wear_levelling/test_apps/pytest_wear_levelling.py b/components/wear_levelling/test_apps/pytest_wear_levelling.py index 0261cd412e..a88d0be4fa 100644 --- a/components/wear_levelling/test_apps/pytest_wear_levelling.py +++ b/components/wear_levelling/test_apps/pytest_wear_levelling.py @@ -1,6 +1,5 @@ # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - import pytest from pytest_embedded import Dut diff --git a/docs/en/contribute/esp-idf-tests-with-pytest.rst b/docs/en/contribute/esp-idf-tests-with-pytest.rst index 30210f694b..a27137ec3a 100644 --- a/docs/en/contribute/esp-idf-tests-with-pytest.rst +++ b/docs/en/contribute/esp-idf-tests-with-pytest.rst @@ -362,16 +362,32 @@ If you need to run a group of test cases, you may run: It would trigger all test cases with the ``[psram]`` tag. -.. warning:: +If you need to run all test cases except for a specific groups, you may run: - You may also see that there are some test scripts with the following statements, which are deprecated. Please use the suggested one as above. +.. code-block:: python - .. code-block:: python + def test_unity_single_dut(dut: IdfDut): + dut.run_all_single_board_cases(group='!psram') - def test_unity_single_dut(dut: IdfDut): - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('*') - dut.expect_unity_test_output() +This code will trigger all test cases except those with the [psram] tag. + +If you need to run a group of test cases filtered by specific attributes, you may run: + +.. code-block:: python + + def test_rtc_xtal32k(dut: Dut) -> None: + dut.run_all_single_board_cases(attributes={'test_env': 'xtal32k'}) + +This command will trigger all tests with the attribute ``test_env`` equal to ``xtal32k``. + +If you need to run tests by specific names, you may run: + +.. code-block:: python + + def test_dut_run_all_single_board_cases(dut): + dut.run_all_single_board_cases(name=["normal_case1", "multiple_stages_test"]) + +This command will trigger ``normal_case1`` and ``multiple_stages_test`` We also provide a fixture ``case_tester`` to trigger all kinds of test cases easier. For example: diff --git a/docs/zh_CN/contribute/esp-idf-tests-with-pytest.rst b/docs/zh_CN/contribute/esp-idf-tests-with-pytest.rst index 7b93b22e3e..99f3d9b6b7 100644 --- a/docs/zh_CN/contribute/esp-idf-tests-with-pytest.rst +++ b/docs/zh_CN/contribute/esp-idf-tests-with-pytest.rst @@ -362,16 +362,32 @@ ESP-IDF 在主机端使用 pytest 框架(以及一些 pytest 插件)来自 此代码会触发模块包含 ``[psram]`` tag 的所有测试用例。 -.. warning:: +如需除了某个特定组之外执行测试用例,可运行: - 你可能还会看到一些包含以下语句的测试脚本,这些脚本已被弃用。请使用上述建议的方法。 +.. code-block:: python - .. code-block:: python + def test_unity_single_dut(dut: IdfDut): + dut.run_all_single_board_cases(group='!psram') - def test_unity_single_dut(dut: IdfDut): - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('*') - dut.expect_unity_test_output() +此代码会触发模块包含 ``[psram]`` tag 以外的所有测试用例。 + +如需按特定属性执行测试用例,可运行: + +.. code-block:: python + + def test_rtc_xtal32k(dut: Dut) -> None: + dut.run_all_single_board_cases(attributes={'test_env': 'xtal32k'}) + +这此代码会触发模块包含具有属性 ``test_env`` 等于 ``xtal32k`` 的测试用例。 + +如需按特定名称执行测试用例,可运行: + +.. code-block:: python + + def test_dut_run_all_single_board_cases(dut): + dut.run_all_single_board_cases(name=["normal_case1", "multiple_stages_test"]) + +这此代码会触发模块包含具有 ``normal_case1`` 和 ``multiple_stages_test`` 名称的测试用例。 我们的 ``case_tester`` 夹具让执行各种测试用例更加简便。例如: