Skip to content

Make integration date assertions timezone-independent#52

Merged
gensyn merged 1 commit into
mainfrom
copilot/investigate-integration-test-failure
May 19, 2026
Merged

Make integration date assertions timezone-independent#52
gensyn merged 1 commit into
mainfrom
copilot/investigate-integration-test-failure

Conversation

Copilot AI commented May 19, 2026

Copy link
Copy Markdown
Contributor

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

    • Replaced timezone-sensitive expectations in integration tests that assumed Python runtime date equals HA local date.
  • Test updates

    • In tests/integration_tests/test_integration.py, updated date assertions in:
      • test_service_updates_last_done_to_today
      • test_last_done_attribute_updated_to_today
      • test_button_press_updates_coordinator_last_done
    • Added homeassistant.util.dt import and aligned assertions to HA time source.
  • Behavioral intent

    • Assertions now validate component behavior against the same clock the component uses, removing midnight/offset-dependent flakiness.
# before
assert coordinator.last_done == date.today()

# after
assert coordinator.last_done == dt_util.now().date()

@gensyn gensyn marked this pull request as ready for review May 19, 2026 07:07
Copilot AI review requested due to automatic review settings May 19, 2026 07:07
@gensyn gensyn merged commit edde93a into main May 19, 2026
5 checks passed
@gensyn gensyn deleted the copilot/investigate-integration-test-failure branch May 19, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_util in the integration test module.
  • Updated three integration tests to compare against dt_util.now().date() (and its string form) rather than date.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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants