mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
ci: set pytest case id to target.config.case_name
This commit is contained in:
32
conftest.py
32
conftest.py
@ -16,15 +16,19 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import List, Optional
|
from typing import Callable, List, Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.fixtures import FixtureRequest
|
from _pytest.fixtures import FixtureRequest
|
||||||
from pytest_embedded.plugin import parse_configuration
|
from pytest_embedded.plugin import parse_configuration
|
||||||
|
from pytest_embedded_idf.app import IdfApp
|
||||||
|
|
||||||
|
|
||||||
def _is_target_marker(marker: str) -> bool:
|
##################
|
||||||
|
# Help Functions #
|
||||||
|
##################
|
||||||
|
def is_target_marker(marker: str) -> bool:
|
||||||
if marker.startswith('esp32'):
|
if marker.startswith('esp32'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -34,12 +38,19 @@ def _is_target_marker(marker: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def format_case_id(target: str, config: str, case: str) -> str:
|
||||||
|
return f'{target}.{config}.{case}'
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
# Fixtures #
|
||||||
|
############
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def target_markers(pytestconfig: Config) -> List[str]:
|
def target_markers(pytestconfig: Config) -> List[str]:
|
||||||
res = []
|
res = []
|
||||||
for item in pytestconfig.getini('markers'):
|
for item in pytestconfig.getini('markers'):
|
||||||
marker = item.split(':')[0]
|
marker = item.split(':')[0]
|
||||||
if _is_target_marker(marker):
|
if is_target_marker(marker):
|
||||||
res.append(marker)
|
res.append(marker)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -76,12 +87,12 @@ def target(request: FixtureRequest, target_markers: List[str], param_markers: Li
|
|||||||
else:
|
else:
|
||||||
target = param_target_markers[0]
|
target = param_target_markers[0]
|
||||||
|
|
||||||
return getattr(request, 'param', None) or target
|
return getattr(request, 'param', None) or request.config.option.__dict__.get('target') or target
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config(request: FixtureRequest) -> Optional[str]:
|
def config(request: FixtureRequest) -> str:
|
||||||
return getattr(request, 'param', None) or request.config.option.__dict__.get('config') or None
|
return getattr(request, 'param', None) or request.config.option.__dict__.get('config') or 'default'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -129,3 +140,12 @@ def build_dir(request: FixtureRequest, app_path: str, target: Optional[str], con
|
|||||||
logging.error(
|
logging.error(
|
||||||
f'no build dir valid. Please build the binary via "idf.py -B {recommend_place} build" and run pytest again')
|
f'no build dir valid. Please build the binary via "idf.py -B {recommend_place} build" and run pytest again')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def junit_properties(app: IdfApp, config: str, test_case_name: str,
|
||||||
|
record_xml_attribute: Callable[[str, object], None]) -> None:
|
||||||
|
"""
|
||||||
|
This fixture is autoused and will modify the junit report test case name to <target>.<config>.<case_name>
|
||||||
|
"""
|
||||||
|
record_xml_attribute('name', format_case_id(app.target, config, test_case_name))
|
||||||
|
Reference in New Issue
Block a user