Attempt to fix flaky nam test (#64613)

pull/64647/head
Erik Montnemery 2022-01-21 18:44:05 +01:00 committed by GitHub
parent 3575009330
commit b3cda6b681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -54,7 +54,10 @@ async def test_sensor(hass):
disabled_by=None,
)
await init_integration(hass)
# Patch return value from utcnow, with offset to make sure the patch is correct
now = utcnow() - timedelta(hours=1)
with patch("homeassistant.components.nam.sensor.utcnow", return_value=now):
await init_integration(hass)
state = hass.states.get("sensor.nettigo_air_monitor_bme280_humidity")
assert state
@ -217,7 +220,7 @@ async def test_sensor(hass):
assert state
assert (
state.state
== (utcnow() - timedelta(seconds=456987)).replace(microsecond=0).isoformat()
== (now - timedelta(seconds=456987)).replace(microsecond=0).isoformat()
)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
assert state.attributes.get(ATTR_STATE_CLASS) is None