mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
ci(pytest): support special markers "supported_targets", "preview_targets", "all_targets"
This commit is contained in:
parent
d0cdfdc5d8
commit
ea4673a3a2
43
conftest.py
43
conftest.py
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
# pylint: disable=W0621 # redefined-outer-name
|
# pylint: disable=W0621 # redefined-outer-name
|
||||||
@ -25,6 +25,9 @@ from _pytest.nodes import Item
|
|||||||
from pytest_embedded.plugin import parse_configuration
|
from pytest_embedded.plugin import parse_configuration
|
||||||
from pytest_embedded_idf.app import IdfApp
|
from pytest_embedded_idf.app import IdfApp
|
||||||
|
|
||||||
|
SUPPORTED_TARGETS = ['esp32', 'esp32s2', 'esp32c3', 'esp32s3']
|
||||||
|
PREVIEW_TARGETS = ['linux', 'esp32h2', 'esp8684']
|
||||||
|
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# Help Functions #
|
# Help Functions #
|
||||||
@ -43,29 +46,13 @@ def format_case_id(target: str, config: str, case: str) -> str:
|
|||||||
return f'{target}.{config}.{case}'
|
return f'{target}.{config}.{case}'
|
||||||
|
|
||||||
|
|
||||||
|
def item_marker_names(item: Item) -> List[str]:
|
||||||
|
return [marker.name for marker in item.iter_markers()]
|
||||||
|
|
||||||
|
|
||||||
############
|
############
|
||||||
# Fixtures #
|
# Fixtures #
|
||||||
############
|
############
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def target_markers(pytestconfig: Config) -> List[str]:
|
|
||||||
res = []
|
|
||||||
for item in pytestconfig.getini('markers'):
|
|
||||||
marker = item.split(':')[0]
|
|
||||||
if is_target_marker(marker):
|
|
||||||
res.append(marker)
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def env_markers(pytestconfig: Config) -> List[str]:
|
|
||||||
res = []
|
|
||||||
for item in pytestconfig.getini('markers'):
|
|
||||||
marker = item.split(':')[0]
|
|
||||||
if not marker.startswith('esp32'):
|
|
||||||
res.append(marker)
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config(request: FixtureRequest) -> str:
|
def config(request: FixtureRequest) -> str:
|
||||||
return getattr(request, 'param', None) or request.config.getoption('config', 'default') # type: ignore
|
return getattr(request, 'param', None) or request.config.getoption('config', 'default') # type: ignore
|
||||||
@ -136,5 +123,17 @@ def pytest_collection_modifyitems(config: Config, items: List[Item]) -> None:
|
|||||||
if not target:
|
if not target:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# add markers for special markers
|
||||||
|
for item in items:
|
||||||
|
if 'supported_targets' in item_marker_names(item):
|
||||||
|
for target in SUPPORTED_TARGETS:
|
||||||
|
item.add_marker(target)
|
||||||
|
if 'preview_targets' in item_marker_names(item):
|
||||||
|
for target in PREVIEW_TARGETS:
|
||||||
|
item.add_marker(target)
|
||||||
|
if 'all_targets' in item_marker_names(item):
|
||||||
|
for target in [*SUPPORTED_TARGETS, *PREVIEW_TARGETS]:
|
||||||
|
item.add_marker(target)
|
||||||
|
|
||||||
# filter all the test cases with "--target"
|
# filter all the test cases with "--target"
|
||||||
items[:] = [item for item in items if target in [marker.name for marker in item.iter_markers()]]
|
items[:] = [item for item in items if target in item_marker_names(item)]
|
||||||
|
@ -5,10 +5,7 @@ import pytest
|
|||||||
from pytest_embedded.dut import Dut
|
from pytest_embedded.dut import Dut
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32
|
@pytest.mark.supported_targets
|
||||||
@pytest.mark.esp32s2
|
|
||||||
@pytest.mark.esp32s3
|
|
||||||
@pytest.mark.esp32c3
|
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
def test_gptimer_example(dut: Dut) -> None:
|
def test_gptimer_example(dut: Dut) -> None:
|
||||||
dut.expect(r'Create timer handle', timeout=5)
|
dut.expect(r'Create timer handle', timeout=5)
|
||||||
|
@ -5,10 +5,7 @@ import pytest
|
|||||||
from pytest_embedded.dut import Dut
|
from pytest_embedded.dut import Dut
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.esp32
|
@pytest.mark.supported_targets
|
||||||
@pytest.mark.esp32s2
|
|
||||||
@pytest.mark.esp32s3
|
|
||||||
@pytest.mark.esp32c3
|
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
def test_timer_group_example(dut: Dut) -> None:
|
def test_timer_group_example(dut: Dut) -> None:
|
||||||
dut.expect(r'Init timer with auto-reload', timeout=5)
|
dut.expect(r'Init timer with auto-reload', timeout=5)
|
||||||
|
@ -14,6 +14,9 @@ markers =
|
|||||||
esp32c3: support esp32c3 target
|
esp32c3: support esp32c3 target
|
||||||
generic: tests should be run on generic runners
|
generic: tests should be run on generic runners
|
||||||
flash_suspend: support flash suspend feature
|
flash_suspend: support flash suspend feature
|
||||||
|
supported_targets: support all supported targets ('esp32', 'esp32s2', 'esp32c3', 'esp32s3')
|
||||||
|
preview_targets: support all preview targets ('linux', 'esp32h2', 'esp8684')
|
||||||
|
all_targets: support all targets, including supported ones and preview ones
|
||||||
|
|
||||||
# log related
|
# log related
|
||||||
log_auto_indent = True
|
log_auto_indent = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user