Avoid creating a task to clear the hass instance at test teardown (#117103)

This commit is contained in:
J. Nick Koston 2024-05-08 16:39:45 -05:00 committed by GitHub
parent 8c37b3afd7
commit ead69af27c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)