mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve report plugin
This commit is contained in:
parent
9cc61d46cf
commit
219a8cdf40
@ -44,6 +44,7 @@ from syrupy.session import SnapshotSession
|
|||||||
|
|
||||||
from homeassistant import block_async_io
|
from homeassistant import block_async_io
|
||||||
from homeassistant.exceptions import ServiceNotFound
|
from homeassistant.exceptions import ServiceNotFound
|
||||||
|
from homeassistant.helpers.json import save_json
|
||||||
|
|
||||||
# Setup patching of recorder functions before any other Home Assistant imports
|
# Setup patching of recorder functions before any other Home Assistant imports
|
||||||
from . import patch_recorder
|
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
|
# Setup patching of dt_util time functions before any other Home Assistant imports
|
||||||
from . import patch_time # noqa: F401, isort:skip
|
from . import patch_time # noqa: F401, isort:skip
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from _pytest.terminal import TerminalReporter
|
from _pytest.terminal import TerminalReporter
|
||||||
|
|
||||||
from homeassistant import components, core as ha, loader, runner
|
from homeassistant import components, core as ha, loader, runner
|
||||||
@ -178,17 +177,18 @@ class PytestExecutionTimeReport:
|
|||||||
if config.option.collectonly:
|
if config.option.collectonly:
|
||||||
return
|
return
|
||||||
|
|
||||||
raw_data: dict[str, list[float]] = {}
|
data: dict[str, float] = {}
|
||||||
for replist in terminalreporter.stats.values():
|
for replist in terminalreporter.stats.values():
|
||||||
for rep in replist:
|
for rep in replist:
|
||||||
if isinstance(rep, pytest.TestReport):
|
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
|
time_report_filename = config.option.execution_time_report_name
|
||||||
file = pathlib.Path(__file__).parents[1].joinpath(time_report_filename)
|
save_json(time_report_filename, data)
|
||||||
with open(file, "w", encoding="utf-8") as fp:
|
|
||||||
json.dump(data, fp, indent=2)
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config: pytest.Config) -> None:
|
def pytest_configure(config: pytest.Config) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user