From 54ad8b8ee91b6c33d8ff0d99153dd95751287a6f Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:50:32 +0100 Subject: [PATCH] Avoid lingering timers in update coordinator tests (#89749) --- tests/helpers/test_update_coordinator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 94a9dfd6b9c..fc6b7bcf757 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -365,7 +365,7 @@ async def test_async_set_updated_data( def update_callback(): updates.append(crd.data) - crd.async_add_listener(update_callback) + remove_callbacks = crd.async_add_listener(update_callback) crd.async_set_updated_data(200) assert updates == [200] assert crd._unsub_refresh is not None @@ -376,6 +376,9 @@ async def test_async_set_updated_data( # We have created a new refresh listener assert crd._unsub_refresh is not old_refresh + # Remove callbacks to avoid lingering timers + remove_callbacks() + async def test_stop_refresh_on_ha_stop( hass: HomeAssistant, crd: update_coordinator.DataUpdateCoordinator[int] @@ -462,7 +465,7 @@ async def test_async_set_update_error( ) -> None: """Test manually setting an update failure.""" update_callback = Mock() - crd.async_add_listener(update_callback) + remove_callbacks = crd.async_add_listener(update_callback) crd.async_set_update_error(aiohttp.ClientError("Client Failure #1")) assert crd.last_update_success is False @@ -486,3 +489,6 @@ async def test_async_set_update_error( assert crd.last_update_success is False assert "Client Failure #2" not in caplog.text update_callback.assert_called_once() + + # Remove callbacks to avoid lingering timers + remove_callbacks()