diff --git a/tests/components/wiz/__init__.py b/tests/components/wiz/__init__.py index fafe00b633df..cddabbca82f7 100644 --- a/tests/components/wiz/__init__.py +++ b/tests/components/wiz/__init__.py @@ -326,7 +326,8 @@ async def async_setup_integration( bulb = wizlight or _mocked_wizlight(device, extended_white_range, bulb_type) with _patch_discovery(), _patch_wizlight(device=bulb): await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) - await hass.async_block_till_done() + # Let the discovery started by async_setup finish while it is patched. + await hass.async_block_till_done(wait_background_tasks=True) return bulb, entry diff --git a/tests/components/wiz/test_init.py b/tests/components/wiz/test_init.py index 3fd02496cdb0..021efd8742e7 100644 --- a/tests/components/wiz/test_init.py +++ b/tests/components/wiz/test_init.py @@ -74,8 +74,8 @@ async def test_wrong_device_now_has_our_ip(hass: HomeAssistant) -> None: bulb.mac = "dddddddddddd" _, entry = await async_setup_integration(hass, wizlight=bulb) assert entry.state is ConfigEntryState.SETUP_RETRY - # Each retry creates a new bulb, so the socket of this one must not leak - bulb.async_close.assert_called_once() + # Each retry creates a new bulb, so every attempt must close its socket + assert bulb.async_close.call_count == bulb.getMac.call_count with _patch_wizlight(): await hass.async_block_till_done(wait_background_tasks=True)