From 219a8cdf408df84b636bad516de43b6cc0f78008 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Thu, 27 Mar 2025 16:53:50 +0100 Subject: [PATCH] Improve report plugin --- tests/conftest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index de62117fecb..f29a78c7816 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -44,6 +44,7 @@ from syrupy.session import SnapshotSession from homeassistant import block_async_io from homeassistant.exceptions import ServiceNotFound +from homeassistant.helpers.json import save_json # Setup patching of recorder functions before any other Home Assistant imports from . import patch_recorder @@ -51,8 +52,6 @@ from . import patch_recorder # Setup patching of dt_util time functions before any other Home Assistant imports from . import patch_time # noqa: F401, isort:skip -import json - from _pytest.terminal import TerminalReporter from homeassistant import components, core as ha, loader, runner @@ -178,17 +177,18 @@ class PytestExecutionTimeReport: if config.option.collectonly: return - raw_data: dict[str, list[float]] = {} + data: dict[str, float] = {} for replist in terminalreporter.stats.values(): for rep in replist: if isinstance(rep, pytest.TestReport): - raw_data.setdefault(rep.location[0], []).append(rep.duration) + location = rep.location[0] + if location not in data: + data[location] = rep.duration + else: + data[location] += rep.duration - data = {filename: sum(values) for filename, values in raw_data.items()} time_report_filename = config.option.execution_time_report_name - file = pathlib.Path(__file__).parents[1].joinpath(time_report_filename) - with open(file, "w", encoding="utf-8") as fp: - json.dump(data, fp, indent=2) + save_json(time_report_filename, data) def pytest_configure(config: pytest.Config) -> None: