diff --git a/tools/ci/idf_pytest/plugin.py b/tools/ci/idf_pytest/plugin.py index 10e4861498..5660c8c730 100644 --- a/tools/ci/idf_pytest/plugin.py +++ b/tools/ci/idf_pytest/plugin.py @@ -233,6 +233,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 e5a9a10ffc..abf7117fca 100644 --- a/tools/ci/idf_pytest/tests/test_get_pytest_cases.py +++ b/tools/ci/idf_pytest/tests/test_get_pytest_cases.py @@ -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'