Add recorder test fixture to enable persistent SQLite database (#121137)

* Add recorder test fixture to enable persistent SQLite database

* Fix tests directly using async_test_home_assistant context manager
This commit is contained in:
Erik Montnemery 2024-07-04 09:59:37 +02:00 committed by GitHub
parent 24f6e6e885
commit d55d02623a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 147 additions and 147 deletions

View file

@ -116,12 +116,18 @@ def test_validate_or_move_away_sqlite_database(
assert util.validate_or_move_away_sqlite_database(dburl) is True
@pytest.mark.skip_on_db_engine(["mysql", "postgresql"])
@pytest.mark.usefixtures("skip_by_db_engine")
@pytest.mark.parametrize("persistent_database", [True])
@pytest.mark.usefixtures("hass_storage") # Prevent test hass from writing to storage
async def test_last_run_was_recently_clean(
async_setup_recorder_instance: RecorderInstanceGenerator, tmp_path: Path
async_setup_recorder_instance: RecorderInstanceGenerator,
) -> None:
"""Test we can check if the last recorder run was recently clean."""
"""Test we can check if the last recorder run was recently clean.
This is only implemented for SQLite.
"""
config = {
recorder.CONF_DB_URL: "sqlite:///" + str(tmp_path / "pytest.db"),
recorder.CONF_COMMIT_INTERVAL: 1,
}
async with async_test_home_assistant() as hass:
@ -850,17 +856,22 @@ async def test_periodic_db_cleanups(
assert str(text_obj) == "PRAGMA wal_checkpoint(TRUNCATE);"
@pytest.mark.skip_on_db_engine(["mysql", "postgresql"])
@pytest.mark.usefixtures("skip_by_db_engine")
@pytest.mark.parametrize("persistent_database", [True])
async def test_write_lock_db(
async_setup_recorder_instance: RecorderInstanceGenerator,
hass: HomeAssistant,
tmp_path: Path,
recorder_db_url: str,
) -> None:
"""Test database write lock."""
"""Test database write lock.
# Use file DB, in memory DB cannot do write locks.
config = {
recorder.CONF_DB_URL: "sqlite:///" + str(tmp_path / "pytest.db?timeout=0.1")
}
This is only supported for SQLite.
Use file DB, in memory DB cannot do write locks.
"""
config = {recorder.CONF_DB_URL: recorder_db_url + "?timeout=0.1"}
instance = await async_setup_recorder_instance(hass, config)
await hass.async_block_till_done()