From ead69af27c08be8c294aaccc62ae21bf85f93211 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 8 May 2024 16:39:45 -0500 Subject: [PATCH] Avoid creating a task to clear the hass instance at test teardown (#117103) --- tests/common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/common.py b/tests/common.py index 41b79f29475..b1e717756af 100644 --- a/tests/common.py +++ b/tests/common.py @@ -353,10 +353,11 @@ async def async_test_home_assistant( hass.set_state(CoreState.running) - async def clear_instance(event): + @callback + def clear_instance(event): """Clear global instance.""" - await asyncio.sleep(0) # Give aiohttp one loop iteration to close - INSTANCES.remove(hass) + # Give aiohttp one loop iteration to close + hass.loop.call_soon(INSTANCES.remove, hass) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, clear_instance)