diff --git a/run/conf_testing/lib/HABAppTests/test_rule/_com_patcher.py b/run/conf_testing/lib/HABAppTests/test_rule/_com_patcher.py index bc6acd4d..89d7979f 100644 --- a/run/conf_testing/lib/HABAppTests/test_rule/_com_patcher.py +++ b/run/conf_testing/lib/HABAppTests/test_rule/_com_patcher.py @@ -15,13 +15,27 @@ from HABApp.config import CONFIG +class PatcherName: + def __init__(self, header: str): + self.header = header + self.logged = False + + class BasePatcher: - def __init__(self, name: str, logger_name: str) -> None: + @staticmethod + def create_name(header: str) -> PatcherName: + return PatcherName(header) + + def __init__(self, name: PatcherName, logger_name: str) -> None: self._log: Final = logging.getLogger('Com').getChild(logger_name) self.name: Final = name self.monkeypatch: Final = MonkeyPatch() def log(self, msg: str) -> None: + if not self.name.logged: + self._log.debug('') + self._log.debug(self.name.header) + self.name.logged = True self._log.debug(msg) def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, @@ -106,7 +120,7 @@ def __init__(self, name: str) -> None: def wrap_sse(self, to_wrap: Callable[[dict], Any]) -> Callable[[dict], Any]: def new_call(_dict: dict) -> Any: - self.log(f'{_dict}') + self.log(f'{"SSE":^6s} {_dict}') return to_wrap(_dict) return new_call @@ -122,13 +136,13 @@ def __init__(self, name: str) -> None: def wrap_msg(self, func: Callable[[str, Any, bool], Any]) -> Callable[[str, Any, bool], Any]: def new_call(topic: str, payload: Any, retain: bool) -> Any: - self.log(f'{"MSG":3s} {"R" if retain else " "} {topic} {payload}') + self.log(f'{"MSG":^6s} {"R" if retain else " "} {topic} {payload}') return func(topic, payload, retain) return new_call def pub_msg(self, func: Callable[[str, Any, int, bool], Any]) -> Callable[[str, Any, int, bool], Any]: async def wrapped_publish(topic: str, payload: Any, qos: int = 0, retain: bool = False) -> Any: - self.log(f'{"PUB":3s} {"R" if retain else " "}{qos:d} {topic} {payload}') + self.log(f'{"PUB":^6s} {"R" if retain else " "}{qos:d} {topic} {payload}') return await func(topic, payload, qos, retain) return wrapped_publish diff --git a/run/conf_testing/lib/HABAppTests/test_rule/test_case.py b/run/conf_testing/lib/HABAppTests/test_rule/test_case.py index c1b4d954..42648812 100644 --- a/run/conf_testing/lib/HABAppTests/test_rule/test_case.py +++ b/run/conf_testing/lib/HABAppTests/test_rule/test_case.py @@ -10,6 +10,7 @@ from HABApp.core.internals import EventBusListener, wrap_func, WrappedFunctionBase from HABAppTests.test_rule._com_patcher import BasePatcher, MqttPatcher, RestPatcher, SsePatcher from HABAppTests.test_rule.test_result import TestResult, TestResultStatus +from HABAppTests.utils import get_file_path_of_obj class TmpLogLevel: @@ -101,11 +102,13 @@ async def run(self, res: TestResult) -> TestResult: async with ExecutionEventCatcher('warning', HABApp.core.const.topics.TOPIC_WARNINGS) as worker_warnings, \ ExecutionEventCatcher('error', HABApp.core.const.topics.TOPIC_ERRORS) as worker_errors: - name = f'{res.cls_name}.{res.test_name}' + try: + suffix = f' (from "{get_file_path_of_obj(self.func)}")' + except ValueError: + suffix = '' + name = RestPatcher.create_name(f'{res.cls_name:s}.{res.test_name:s}{suffix:s}') b = BasePatcher(name, 'TC') - b.log('') - b.log(name) try: with RestPatcher(name), SsePatcher(name), MqttPatcher(name): diff --git a/run/conf_testing/lib/HABAppTests/test_rule/test_runner_rule.py b/run/conf_testing/lib/HABAppTests/test_rule/test_runner_rule.py index 3ef48522..c719340d 100644 --- a/run/conf_testing/lib/HABAppTests/test_rule/test_runner_rule.py +++ b/run/conf_testing/lib/HABAppTests/test_rule/test_runner_rule.py @@ -1,12 +1,14 @@ import logging import HABApp +from HABApp.core import shutdown from HABApp.core.const.topics import TOPIC_FILES from HABApp.core.lib import SingleTask +from HABApp.core.wrapper import ignore_exception from HABAppTests.test_rule.test_case import TestResult, TestResultStatus from .test_rule import TestBaseRule, TestRuleStatus -from HABApp.core import shutdown + log = logging.getLogger('HABApp.Tests') @@ -36,6 +38,7 @@ def _get_next_rule(self) -> TestBaseRule | None: return rule return None + @ignore_exception async def _run_tests(self) -> None: results: list[TestResult] = []