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)