From 9e1a670e6eada513d68611f7d488651fd2de598d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 13 Apr 2023 17:03:52 +0200 Subject: [PATCH] Fail CI on lingering timers (part 2) (#89976) * Fail CI on lingering timers (part 2) * Improve error message * Adjust tts --- tests/components/tts/test_init.py | 1 + tests/conftest.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/components/tts/test_init.py b/tests/components/tts/test_init.py index b6004c13d46..0a4f5a273be 100644 --- a/tests/components/tts/test_init.py +++ b/tests/components/tts/test_init.py @@ -765,6 +765,7 @@ async def test_setup_component_test_with_cache_dir( await get_media_source_url(hass, calls[0].data[ATTR_MEDIA_CONTENT_ID]) == "/api/tts_proxy/42f18378fd4393d18c8dd11d03fa9563c1e54491_en_-_test.mp3" ) + await hass.async_block_till_done() async def test_setup_component_test_with_error_on_get_tts(hass: HomeAssistant) -> None: diff --git a/tests/conftest.py b/tests/conftest.py index b1d0a0a7de8..b076a394a22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -47,7 +47,7 @@ from homeassistant.components.websocket_api.http import URL from homeassistant.config import YAML_CONFIG_FILE from homeassistant.config_entries import ConfigEntries, ConfigEntry from homeassistant.const import HASSIO_USER_NAME -from homeassistant.core import CoreState, HomeAssistant +from homeassistant.core import CoreState, HassJob, HomeAssistant from homeassistant.helpers import ( area_registry as ar, config_entry_oauth2_flow, @@ -58,7 +58,7 @@ from homeassistant.helpers import ( recorder as recorder_helper, ) from homeassistant.helpers.typing import ConfigType -from homeassistant.setup import async_setup_component +from homeassistant.setup import BASE_PLATFORMS, async_setup_component from homeassistant.util import dt as dt_util, location from homeassistant.util.json import json_loads @@ -273,8 +273,12 @@ def expected_lingering_timers() -> bool: This should be removed when all lingering timers have been cleaned up. """ current_test = os.getenv("PYTEST_CURRENT_TEST") - if current_test and current_test.startswith("tests/components"): - # As a starting point, we ignore components + if ( + current_test + and current_test.startswith("tests/components/") + and current_test.split("/")[2] not in BASE_PLATFORMS + ): + # As a starting point, we ignore non-platform components return True return False @@ -341,6 +345,8 @@ def verify_cleanup( if not handle.cancelled(): if expected_lingering_timers: _LOGGER.warning("Lingering timer after test %r", handle) + elif handle._args and isinstance(job := handle._args[0], HassJob): + pytest.fail(f"Lingering timer after job {repr(job)}") else: pytest.fail(f"Lingering timer after test {repr(handle)}") handle.cancel()