Skip to content

Commit 4a19463

Browse files
committed
feat: added skip_if_soc marker for idf target
1 parent 256746f commit 4a19463

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

pytest-embedded-idf/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ requires-python = ">=3.7"
3333
dependencies = [
3434
"pytest-embedded~=1.12.1",
3535
"esp-idf-panic-decoder",
36+
"idf-build-apps~=2.5.3"
3637
]
3738

3839
[project.optional-dependencies]

pytest-embedded-idf/tests/test_idf.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,3 +987,52 @@ def test_python_case(dut):
987987
assert junit_report[0].attrib['is_unity_case'] == '0' # Python test case
988988
for testcase in junit_report[1:]:
989989
assert testcase.attrib['is_unity_case'] == '1' # Other test cases
990+
991+
992+
def test_skip_if_soc(testdir):
993+
EMBEDDED_SERVICES = ['--embedded-services', 'esp,idf']
994+
995+
def run_pytest_with_target(target):
996+
return testdir.runpytest(*EMBEDDED_SERVICES, '--target', target)
997+
998+
testdir.makepyfile("""
999+
import pytest
1000+
from idf_build_apps.constants import SUPPORTED_TARGETS
1001+
1002+
@pytest.mark.skip_if_soc("SOC_ULP_LP_UART_SUPPORTED == 1")
1003+
@pytest.mark.parametrize('target', ['esp32', 'esp32s3', 'esp32c6'], indirect=True)
1004+
def test_lp_uart_wakeup():
1005+
pass
1006+
1007+
@pytest.mark.skip_if_soc("SOC_BLE_SUPPORTED == 1")
1008+
@pytest.mark.parametrize('target', SUPPORTED_TARGETS, indirect=True)
1009+
def test_ble():
1010+
pass
1011+
1012+
@pytest.mark.skip_if_soc("SOC_ADC_SAMPLE_FREQ_THRES_HIGH == 83333")
1013+
@pytest.mark.parametrize('target', SUPPORTED_TARGETS, indirect=True)
1014+
def test_adc():
1015+
pass
1016+
1017+
""")
1018+
1019+
result = testdir.runpytest('-s', *EMBEDDED_SERVICES)
1020+
result.assert_outcomes(passed=14, failed=0, skipped=5)
1021+
1022+
testdir.makepyfile("""
1023+
import pytest
1024+
1025+
@pytest.mark.skip_if_soc("SOC_ULP_LP_UART_SUPPORTED == 1")
1026+
def test_from_args():
1027+
pass
1028+
1029+
""")
1030+
1031+
results = [
1032+
(run_pytest_with_target('esp32'), {'passed': 0, 'failed': 0, 'skipped': 1}),
1033+
(run_pytest_with_target('esp32c5'), {'passed': 1, 'failed': 0, 'skipped': 0}),
1034+
(run_pytest_with_target('auto'), {'passed': 1, 'failed': 0, 'skipped': 0}),
1035+
]
1036+
1037+
for result, expected in results:
1038+
result.assert_outcomes(**expected)

pytest-embedded/pytest_embedded/plugin.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ def pytest_configure(config: Config) -> None:
12041204
add_target_as_marker=_str_bool(config.getoption('add_target_as_marker', False)),
12051205
)
12061206
config.pluginmanager.register(config.stash[_pytest_embedded_key])
1207+
config.addinivalue_line('markers', 'skip_if_soc')
12071208

12081209

12091210
def pytest_unconfigure(config: Config) -> None:
@@ -1252,7 +1253,32 @@ def _duplicate_items(items: t.List[_T]) -> t.List[_T]:
12521253
return duplicates
12531254

12541255
@pytest.hookimpl(hookwrapper=True, trylast=True)
1255-
def pytest_collection_modifyitems(self, items: t.List[Function]):
1256+
def pytest_collection_modifyitems(self, config: Config, items: t.List[Function]):
1257+
for item in items:
1258+
skip_marker = item.get_closest_marker('skip_if_soc')
1259+
if not skip_marker:
1260+
continue
1261+
1262+
target = config.getoption('--target', None)
1263+
if hasattr(item, 'callspec'):
1264+
target = item.callspec.params.get('target', None)
1265+
if target == 'auto' or target is None:
1266+
logging.warning(
1267+
f"Test item '{item.originalname}': "
1268+
"Ensure 'target' is included in the test @pytest.mark.parametrize when using 'skip_if_soc', "
1269+
'or provide the --target argument when running tests.'
1270+
)
1271+
continue
1272+
1273+
from idf_build_apps.manifest.if_parser import BOOL_EXPR
1274+
1275+
stm = BOOL_EXPR.parseString(skip_marker.args[0])[0]
1276+
if not stm.get_value(target, None):
1277+
from _pytest.mark import MARK_GEN
1278+
1279+
reason = f'Filtered by {skip_marker.args[0]}, for {target}.'
1280+
item.add_marker(MARK_GEN.skip(reason=reason))
1281+
12561282
if self.add_target_as_marker:
12571283
for item in items:
12581284
item_target = item.callspec.getparam('target')

0 commit comments

Comments
 (0)