From 056601127b6ba5d6fbcd42f184e902cae1e28687 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 22 Nov 2022 11:13:14 +0800 Subject: [PATCH] ci: add `temp_skip_ci` marker to simplify markers example: `@pytest.mark.temp_skip_ci(targets=['esp32'])` --- conftest.py | 32 ++++++++++++++++++++++++++++---- pytest.ini | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/conftest.py b/conftest.py index de22ce2a1e..a6a0595ab3 100644 --- a/conftest.py +++ b/conftest.py @@ -126,7 +126,7 @@ def log_minimum_free_heap_size(dut: IdfDut, config: str) -> Callable[..., None]: @pytest.fixture -def case_tester(dut: IdfDut, **kwargs): # type: ignore +def case_tester(dut: IdfDut, **kwargs): # type: ignore yield CaseTester(dut, **kwargs) @@ -326,15 +326,39 @@ class IdfPytestEmbedded: # add markers for special markers for item in items: + skip_ci_marker = item.get_closest_marker('temp_skip_ci') + skip_ci_targets: List[str] = [] + if skip_ci_marker: + # `temp_skip_ci` should always use keyword arguments `targets` and `reason` + if not skip_ci_marker.kwargs.get('targets') or not skip_ci_marker.kwargs.get('reason'): + raise ValueError( + f'`temp_skip_ci` should always use keyword arguments `targets` and `reason`. ' + f'For example: ' + f'`@pytest.mark.temp_skip_ci(targets=["esp32"], reason="IDF-xxxx, will fix it ASAP")`' + ) + + skip_ci_targets = skip_ci_marker.kwargs['targets'] + if 'supported_targets' in item.keywords: for _target in SUPPORTED_TARGETS: - item.add_marker(_target) + if _target not in skip_ci_targets: + item.add_marker(_target) if 'preview_targets' in item.keywords: for _target in PREVIEW_TARGETS: - item.add_marker(_target) + if _target not in skip_ci_targets: + item.add_marker(_target) if 'all_targets' in item.keywords: for _target in [*SUPPORTED_TARGETS, *PREVIEW_TARGETS]: - item.add_marker(_target) + if _target not in skip_ci_targets: + item.add_marker(_target) + + # `temp_skip_ci(targets=...)` can't work with specified single target + for skip_ci_target in skip_ci_targets: + if skip_ci_target in item.keywords: + raise ValueError( + '`skip_ci_targets` can only work with ' + '`supported_targets`, `preview_targets`, `all_targets` markers' + ) # add 'xtal_40mhz' tag as a default tag for esp32c2 target for item in items: diff --git a/pytest.ini b/pytest.ini index 7789a6e82c..37c7266ea5 100644 --- a/pytest.ini +++ b/pytest.ini @@ -30,6 +30,7 @@ markers = supported_targets: support all supported targets ('esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2') preview_targets: support all preview targets ('linux', 'esp32h4', 'esp32c6') all_targets: support all targets, including supported ones and preview ones + temp_skip_ci: temp skip ci for specified targets, can only work with `supported_targets`, `preview_targets`, `all_targets` # env markers generic: tests should be run on generic runners