Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update switch tests to avoid patching utcnow #93491

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/components/switch/test_device_condition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The test for switch device automation."""
from datetime import timedelta
from unittest.mock import patch

from freezegun import freeze_time
import pytest

import homeassistant.components.automation as automation
Expand Down Expand Up @@ -232,8 +232,7 @@ async def test_if_fires_on_for_condition(

ent1, ent2, ent3 = platform.ENTITIES

with patch("homeassistant.core.dt_util.utcnow") as mock_utcnow:
mock_utcnow.return_value = point1
with freeze_time(point1) as freezer:
assert await async_setup_component(
hass,
automation.DOMAIN,
Expand Down Expand Up @@ -271,7 +270,7 @@ async def test_if_fires_on_for_condition(
assert len(calls) == 0

# Time travel 10 secs into the future
mock_utcnow.return_value = point2
freezer.move_to(point2)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 0
Expand All @@ -282,7 +281,7 @@ async def test_if_fires_on_for_condition(
assert len(calls) == 0

# Time travel 20 secs into the future
mock_utcnow.return_value = point3
freezer.move_to(point3)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
Expand Down