From 61cea28081ef3d8a7c1cad619520b5a05a1c7a94 Mon Sep 17 00:00:00 2001 From: Evgeny Torbin Date: Fri, 13 Mar 2026 15:28:19 +0100 Subject: [PATCH] ci: fix test case markers when put targets as params --- tools/ci/idf_pytest/plugin.py | 8 ++++++- .../idf_pytest/tests/test_get_pytest_cases.py | 22 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/ci/idf_pytest/plugin.py b/tools/ci/idf_pytest/plugin.py index e551da13abe..4508cce4ba5 100644 --- a/tools/ci/idf_pytest/plugin.py +++ b/tools/ci/idf_pytest/plugin.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import os import typing as t @@ -197,6 +197,12 @@ class IdfPytestEmbedded: if 'all_targets' in item.keywords: for _target in [*SUPPORTED_TARGETS, *PREVIEW_TARGETS]: item.add_marker(_target) + + # add single-dut "target" as param + _item_target_param = self.get_param(item, 'target', None) + if case.is_single_dut_test_case and _item_target_param and _item_target_param not in case.all_markers: + item.add_marker(_item_target_param) + items[:] = [_item for _item in items if _item in item_to_case_dict] # 3.1. CollectMode.SINGLE_SPECIFIC, like `pytest --target esp32` diff --git a/tools/ci/idf_pytest/tests/test_get_pytest_cases.py b/tools/ci/idf_pytest/tests/test_get_pytest_cases.py index e5a9a10ffca..d327984f6c4 100644 --- a/tools/ci/idf_pytest/tests/test_get_pytest_cases.py +++ b/tools/ci/idf_pytest/tests/test_get_pytest_cases.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import textwrap from pathlib import Path @@ -14,6 +14,13 @@ import pytest def test_foo_single(dut): pass +@pytest.mark.parametrize('target', [ + 'esp32', + 'esp32c3', +]) +def test_foo_single_with_param(dut): + pass + @pytest.mark.parametrize( 'count, target', [ (2, 'esp32|esp32s2'), @@ -38,8 +45,11 @@ def test_get_pytest_cases_single_specific(work_dirpath: Path) -> None: script.write_text(TEMPLATE_SCRIPT) cases = get_pytest_cases([str(work_dirpath)], 'esp32') - assert len(cases) == 1 + assert len(cases) == 2 assert cases[0].targets == ['esp32'] + assert cases[0].name == 'test_foo_single' + assert cases[1].targets == ['esp32'] + assert cases[1].name == 'test_foo_single_with_param' def test_get_pytest_cases_multi_specific(work_dirpath: Path) -> None: @@ -69,7 +79,7 @@ def test_get_pytest_cases_all(work_dirpath: Path) -> None: script.write_text(TEMPLATE_SCRIPT) cases = get_pytest_cases([str(work_dirpath)], CollectMode.ALL) - assert len(cases) == 6 + assert len(cases) == 8 assert cases[0].targets == ['esp32', 'esp32s2'] assert cases[0].name == 'test_foo_multi' @@ -88,6 +98,12 @@ def test_get_pytest_cases_all(work_dirpath: Path) -> None: assert cases[5].targets == ['esp32s2'] assert cases[5].name == 'test_foo_single' + assert cases[6].targets == ['esp32'] + assert cases[6].name == 'test_foo_single_with_param' + + assert cases[7].targets == ['esp32c3'] + assert cases[7].name == 'test_foo_single_with_param' + def test_multi_with_marker_and_app_path(work_dirpath: Path) -> None: script = work_dirpath / 'pytest_multi_with_marker_and_app_path.py'