Make integration date assertions timezone-independent#52
Merged
Conversation
Agent-Logs-Url: https://github.com/gensyn/task_tracker/sessions/2b70d9e9-8920-4b9a-be7c-4d78c6a91117 Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
gensyn
May 19, 2026 06:54
View session
There was a problem hiding this comment.
Pull request overview
This PR updates integration tests to assert “today” using Home Assistant’s local-time clock (homeassistant.util.dt.now().date()) instead of Python’s system date (datetime.date.today()), eliminating false failures around UTC day boundaries.
Changes:
- Imported
homeassistant.util.dt as dt_utilin the integration test module. - Updated three integration tests to compare against
dt_util.now().date()(and its string form) rather thandate.today().
Comments suppressed due to low confidence (2)
tests/integration_tests/test_integration.py:220
- Same midnight-boundary flakiness risk as above: dt_util.now().date() is evaluated at assertion time, not when the service set last_done. Capture expected_today before invoking the service and compare the attribute to that.
)
await hass.async_block_till_done()
state = hass.states.get("sensor.task_tracker_water_plants")
assert state.attributes["last_done"] == str(dt_util.now().date())
tests/integration_tests/test_integration.py:308
- dt_util.now().date() is evaluated after the button press completes; if execution crosses local midnight, the stored last_done (set at press time) can differ from the asserted value. Capture expected_today before the button press and assert against that to avoid midnight-boundary flakes.
blocking=True,
)
await hass.async_block_till_done()
coordinator = hass.data[DOMAIN]["e1"]
assert coordinator.last_done == dt_util.now().date()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
201
to
205
| await hass.async_block_till_done() | ||
|
|
||
| coordinator = hass.data[DOMAIN]["e1"] | ||
| assert coordinator.last_done == date.today() | ||
| assert coordinator.last_done == dt_util.now().date() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integration tests were comparing against
date.today()(system/UTC context), while the integration computes “today” from Home Assistant local time (dt_util.now().date()). This created false failures around UTC day boundaries after merge.Root cause addressed
Test updates
tests/integration_tests/test_integration.py, updated date assertions in:test_service_updates_last_done_to_todaytest_last_done_attribute_updated_to_todaytest_button_press_updates_coordinator_last_donehomeassistant.util.dtimport and aligned assertions to HA time source.Behavioral intent