From 67de1d346631d37c1bf7c8e5ee71aebb9a38b2ea Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 28 Aug 2020 22:06:06 -0500 Subject: [PATCH] Fix sun test to patch time since it is now refetched (#39372) This accounts for the fix in #39335 --- tests/components/sun/test_init.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/components/sun/test_init.py b/tests/components/sun/test_init.py index 56ac683582a..36eaa8398ac 100644 --- a/tests/components/sun/test_init.py +++ b/tests/components/sun/test_init.py @@ -120,11 +120,12 @@ async def test_state_change(hass, legacy_patchable_time): assert sun.STATE_BELOW_HORIZON == hass.states.get(sun.ENTITY_ID).state - hass.bus.async_fire( - ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: test_time + timedelta(seconds=5)} - ) - - await hass.async_block_till_done() + patched_time = test_time + timedelta(seconds=5) + with patch( + "homeassistant.helpers.condition.dt_util.utcnow", return_value=patched_time + ): + hass.bus.async_fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: patched_time}) + await hass.async_block_till_done() assert sun.STATE_ABOVE_HORIZON == hass.states.get(sun.ENTITY_ID).state