2024-01-12 08:42:00 -05:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
2023-11-28 08:38:47 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from idf_pytest.constants import CollectMode
|
2023-12-18 09:29:58 -05:00
|
|
|
from idf_pytest.script import get_pytest_cases
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
TEMPLATE_SCRIPT = '''
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
def test_foo_single(dut):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count, target', [
|
|
|
|
(2, 'esp32|esp32s2'),
|
|
|
|
(3, 'esp32s2|esp32s2|esp32s3'),
|
|
|
|
], indirect=True
|
|
|
|
)
|
|
|
|
def test_foo_multi(dut):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'count', [2], indirect=True
|
|
|
|
)
|
|
|
|
def test_foo_multi_with_marker(dut):
|
|
|
|
pass
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_pytest_cases_single_specific(tmp_path: Path) -> None:
|
|
|
|
script = tmp_path / 'pytest_get_pytest_cases_single_specific.py'
|
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
|
|
|
cases = get_pytest_cases([str(tmp_path)], 'esp32')
|
|
|
|
|
|
|
|
assert len(cases) == 1
|
|
|
|
assert cases[0].targets == ['esp32']
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_pytest_cases_multi_specific(tmp_path: Path) -> None:
|
|
|
|
script = tmp_path / 'pytest_get_pytest_cases_multi_specific.py'
|
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
2024-01-12 08:42:00 -05:00
|
|
|
cases = get_pytest_cases([str(tmp_path)], 'esp32s2,esp32s2, esp32s3')
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
assert len(cases) == 1
|
|
|
|
assert cases[0].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
|
2024-01-12 08:42:00 -05:00
|
|
|
cases = get_pytest_cases([str(tmp_path)], 'esp32s3,esp32s2,esp32s2') # order matters
|
|
|
|
assert len(cases) == 0
|
|
|
|
|
2023-11-28 08:38:47 -05:00
|
|
|
|
|
|
|
def test_get_pytest_cases_multi_all(tmp_path: Path) -> None:
|
|
|
|
script = tmp_path / 'pytest_get_pytest_cases_multi_all.py'
|
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
|
|
|
cases = get_pytest_cases([str(tmp_path)], CollectMode.MULTI_ALL_WITH_PARAM)
|
|
|
|
|
|
|
|
assert len(cases) == 2
|
|
|
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
|
|
|
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_pytest_cases_all(tmp_path: Path) -> None:
|
|
|
|
script = tmp_path / 'pytest_get_pytest_cases_all.py'
|
|
|
|
script.write_text(TEMPLATE_SCRIPT)
|
|
|
|
cases = get_pytest_cases([str(tmp_path)], CollectMode.ALL)
|
|
|
|
|
|
|
|
assert len(cases) == 6
|
|
|
|
assert cases[0].targets == ['esp32', 'esp32s2']
|
|
|
|
assert cases[0].name == 'test_foo_multi'
|
|
|
|
|
|
|
|
assert cases[1].targets == ['esp32s2', 'esp32s2', 'esp32s3']
|
|
|
|
assert cases[1].name == 'test_foo_multi'
|
|
|
|
|
|
|
|
assert cases[2].targets == ['esp32', 'esp32']
|
|
|
|
assert cases[2].name == 'test_foo_multi_with_marker'
|
|
|
|
|
|
|
|
assert cases[3].targets == ['esp32s2', 'esp32s2']
|
|
|
|
assert cases[3].name == 'test_foo_multi_with_marker'
|
|
|
|
|
|
|
|
assert cases[4].targets == ['esp32']
|
|
|
|
assert cases[4].name == 'test_foo_single'
|
|
|
|
|
|
|
|
assert cases[5].targets == ['esp32s2']
|
|
|
|
assert cases[5].name == 'test_foo_single'
|