Fix flaky datetime test (#68524)
This commit is contained in:
parent
0c45241d43
commit
c9cc2eb7c8
2 changed files with 12 additions and 3 deletions
|
@ -797,6 +797,8 @@ def enable_nightly_purge():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hass_recorder(enable_nightly_purge, enable_statistics, hass_storage):
|
def hass_recorder(enable_nightly_purge, enable_statistics, hass_storage):
|
||||||
"""Home Assistant fixture with in-memory recorder."""
|
"""Home Assistant fixture with in-memory recorder."""
|
||||||
|
original_tz = dt_util.DEFAULT_TIME_ZONE
|
||||||
|
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None
|
stats = recorder.Recorder.async_periodic_statistics if enable_statistics else None
|
||||||
nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
|
nightly = recorder.Recorder.async_nightly_tasks if enable_nightly_purge else None
|
||||||
|
@ -821,6 +823,9 @@ def hass_recorder(enable_nightly_purge, enable_statistics, hass_storage):
|
||||||
yield setup_recorder
|
yield setup_recorder
|
||||||
hass.stop()
|
hass.stop()
|
||||||
|
|
||||||
|
# Restore timezone, it is set when creating the hass object
|
||||||
|
dt_util.DEFAULT_TIME_ZONE = original_tz
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def recorder_mock(enable_nightly_purge, enable_statistics, hass):
|
async def recorder_mock(enable_nightly_purge, enable_statistics, hass):
|
||||||
|
|
|
@ -67,9 +67,13 @@ def test_repr_helper():
|
||||||
assert util.repr_helper(5) == "5"
|
assert util.repr_helper(5) == "5"
|
||||||
assert util.repr_helper(True) == "True"
|
assert util.repr_helper(True) == "True"
|
||||||
assert util.repr_helper({"test": 1}) == "test=1"
|
assert util.repr_helper({"test": 1}) == "test=1"
|
||||||
assert (
|
|
||||||
util.repr_helper(datetime(1986, 7, 9, 12, 0, 0)) == "1986-07-09T12:00:00+00:00"
|
tz = dt_util.get_time_zone("Europe/Copenhagen")
|
||||||
)
|
with patch("homeassistant.util.dt.DEFAULT_TIME_ZONE", tz):
|
||||||
|
assert (
|
||||||
|
util.repr_helper(datetime(1986, 7, 9, 12, 0, 0))
|
||||||
|
== "1986-07-09T12:00:00+02:00"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_convert():
|
def test_convert():
|
||||||
|
|
Loading…
Add table
Reference in a new issue