From 333d5a92519b31c31102580e6ba7f78e0ba14820 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 9 May 2024 09:14:07 -0500 Subject: [PATCH] Speed up test teardown when no config entries are loaded (#117095) Avoid the gather call when there are no loaded config entries --- tests/conftest.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6a16082a87f..a034ec7ad8f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,7 +48,7 @@ from homeassistant.components.websocket_api.auth import ( ) from homeassistant.components.websocket_api.http import URL from homeassistant.config import YAML_CONFIG_FILE -from homeassistant.config_entries import ConfigEntries, ConfigEntry +from homeassistant.config_entries import ConfigEntries, ConfigEntry, ConfigEntryState from homeassistant.const import HASSIO_USER_NAME from homeassistant.core import CoreState, HassJob, HomeAssistant from homeassistant.helpers import ( @@ -558,12 +558,18 @@ async def hass( # Config entries are not normally unloaded on HA shutdown. They are unloaded here # to ensure that they could, and to help track lingering tasks and timers. - await asyncio.gather( - *( - create_eager_task(config_entry.async_unload(hass)) - for config_entry in hass.config_entries.async_entries() + loaded_entries = [ + entry + for entry in hass.config_entries.async_entries() + if entry.state is ConfigEntryState.LOADED + ] + if loaded_entries: + await asyncio.gather( + *( + create_eager_task(config_entry.async_unload(hass)) + for config_entry in loaded_entries + ) ) - ) await hass.async_stop(force=True)