1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Improve recorder setup in tests (#68333)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Erik Montnemery
2022-03-21 23:49:18 +01:00
committed by GitHub
parent 653305b998
commit 247af2e74f
2 changed files with 34 additions and 10 deletions

View File

@@ -41,6 +41,7 @@ from tests.common import ( # noqa: E402, isort:skip
MockConfigEntry,
MockUser,
async_fire_mqtt_message,
async_init_recorder_component,
async_test_home_assistant,
get_test_home_assistant,
init_recorder_component,
@@ -821,6 +822,28 @@ def hass_recorder(enable_nightly_purge, enable_statistics, hass_storage):
hass.stop()
@pytest.fixture
async def recorder_mock(enable_nightly_purge, enable_statistics, hass):
"""Fixture with in-memory recorder."""
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None
nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
with patch(
"homeassistant.components.recorder.Recorder.async_periodic_statistics",
side_effect=stats,
autospec=True,
), patch(
"homeassistant.components.recorder.Recorder.async_nightly_tasks",
side_effect=nightly,
autospec=True,
):
await async_init_recorder_component(hass)
await hass.async_start()
await hass.async_block_till_done()
await hass.async_add_executor_job(
hass.data[recorder.DATA_INSTANCE].block_till_done
)
@pytest.fixture
def mock_integration_frame():
"""Mock as if we're calling code from inside an integration."""