From 2620a95944e2f364487caaa849cf6f3219a50a52 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 31 Dec 2019 17:10:39 +0100 Subject: [PATCH] Improve Withings tests in different time zone (#30326) * Improve Withings tests in different time zone * Address code review comment * Spelling error in code doc --- tests/components/withings/test_common.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/components/withings/test_common.py b/tests/components/withings/test_common.py index 6c8c0a4c310..acb69dddf4e 100644 --- a/tests/components/withings/test_common.py +++ b/tests/components/withings/test_common.py @@ -1,5 +1,6 @@ """Tests for the Withings component.""" from datetime import timedelta +from unittest.mock import patch from asynctest import MagicMock import pytest @@ -10,18 +11,10 @@ from homeassistant.components.withings.common import ( NotAuthenticatedError, WithingsDataManager, ) -from homeassistant.config import async_process_ha_core_config from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.util import dt -DEFAULT_TIME_ZONE = dt.DEFAULT_TIME_ZONE - - -def teardown(): - """Ensure the time zone is reverted after tests finish.""" - dt.set_default_time_zone(DEFAULT_TIME_ZONE) - @pytest.fixture(name="withings_api") def withings_api_fixture() -> WithingsApi: @@ -34,6 +27,17 @@ def withings_api_fixture() -> WithingsApi: return withings_api +@pytest.fixture +def mock_time_zone(): + """Provide an alternative time zone.""" + patch_time_zone = patch( + "homeassistant.util.dt.DEFAULT_TIME_ZONE", + new=dt.get_time_zone("America/Los_Angeles"), + ) + with patch_time_zone: + yield + + @pytest.fixture(name="data_manager") def data_manager_fixture(hass, withings_api: WithingsApi) -> WithingsDataManager: """Provide data manager.""" @@ -118,13 +122,9 @@ async def test_data_manager_call_throttle_disabled( async def test_data_manager_update_sleep_date_range( - hass: HomeAssistant, data_manager: WithingsDataManager, + hass: HomeAssistant, data_manager: WithingsDataManager, mock_time_zone ) -> None: """Test method.""" - await async_process_ha_core_config( - hass=hass, config={"time_zone": "America/Los_Angeles"} - ) - update_start_time = dt.now() await data_manager.update_sleep()