From c2a239bd6b411cd35bcc01a2172885c154e4dbba Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 1 Dec 2021 11:35:56 +0800 Subject: [PATCH] ci: set pytest case id to target.config.case_name --- conftest.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/conftest.py b/conftest.py index e72544451a..38febbbbfb 100644 --- a/conftest.py +++ b/conftest.py @@ -16,15 +16,19 @@ import logging import os import sys -from typing import List, Optional +from typing import Callable, List, Optional import pytest from _pytest.config import Config from _pytest.fixtures import FixtureRequest 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'): return True @@ -34,12 +38,19 @@ def _is_target_marker(marker: str) -> bool: return False +def format_case_id(target: str, config: str, case: str) -> str: + return f'{target}.{config}.{case}' + + +############ +# 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): + if is_target_marker(marker): res.append(marker) return res @@ -76,12 +87,12 @@ def target(request: FixtureRequest, target_markers: List[str], param_markers: Li else: 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 -def config(request: FixtureRequest) -> Optional[str]: - return getattr(request, 'param', None) or request.config.option.__dict__.get('config') or None +def config(request: FixtureRequest) -> str: + return getattr(request, 'param', None) or request.config.option.__dict__.get('config') or 'default' @pytest.fixture @@ -129,3 +140,12 @@ def build_dir(request: FixtureRequest, app_path: str, target: Optional[str], con logging.error( f'no build dir valid. Please build the binary via "idf.py -B {recommend_place} build" and run pytest again') 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 .. + """ + record_xml_attribute('name', format_case_id(app.target, config, test_case_name))