Add __init__ lifecycle tests #5

Merged
mat merged 3 commits from test/init into main 2026-04-24 12:38:37 +00:00
Owner

Summary

  • Adds tests/test_init.py with two cases:
    • test_setup_entry_authenticates_and_loads: verifies the happy path — entry reaches LOADED, authenticate() is called with stored credentials, hass.data[DOMAIN]['cookies'] is populated.
    • test_unload_entry_cleans_up: marked strict-xfail pending finding C5 (async_unload_entry pops entry.entry_id, but setup never stores anything there). The test will flip to xpass and must be removed once C5 is fixed.

Depends on

  • #3 (test infrastructure).

Test plan

  • pytest tests/test_init.py — 1 passed, 1 xfailed
  • When C5 is fixed, the xfail becomes strict-failing (xpass) — the C5 PR should drop the marker.
## Summary - Adds `tests/test_init.py` with two cases: - `test_setup_entry_authenticates_and_loads`: verifies the happy path — entry reaches `LOADED`, `authenticate()` is called with stored credentials, `hass.data[DOMAIN]['cookies']` is populated. - `test_unload_entry_cleans_up`: marked **strict-xfail** pending finding **C5** (`async_unload_entry` pops `entry.entry_id`, but setup never stores anything there). The test will flip to xpass and must be removed once C5 is fixed. ## Depends on - #3 (test infrastructure). ## Test plan - [x] `pytest tests/test_init.py` — 1 passed, 1 xfailed - [ ] When C5 is fixed, the xfail becomes strict-failing (xpass) — the C5 PR should drop the marker.
(AI) Add pytest infrastructure
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
253d3d9515
Adds the plumbing needed to run Home Assistant custom-integration tests:

- `requirements-test.txt` pins `pytest-homeassistant-custom-component`
  (which transitively pulls `homeassistant`) and the runtime dependency
  `comwatt-client`.
- `pytest.ini` enables `asyncio_mode = auto` and points pytest at
  `tests/`.
- `tests/conftest.py` loads the pytest-homeassistant-custom-component
  plugin, auto-enables custom integrations, and exposes a
  `mock_comwatt_client` fixture that patches every import site of
  `ComwattClient` used by the integration.
- `tests/test_smoke.py` exercises the plumbing and asserts basic
  manifest/domain invariants.

Follow-up PRs will add config-flow, init, sensor, and switch tests on
top of this scaffolding.
🐛 (AI) Fix cookie jar mock in test fixture
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
05511bb47b
`_make_fake_client` assigned a plain list to `session.cookies` then
tried to attach a `get_dict` attribute to it, which fails because
lists don't accept arbitrary attributes. Introduce `_FakeCookieJar`, a
list subclass that answers `get_dict()` the way `requests`' own
`RequestsCookieJar` does, so both iteration (used by the config flow)
and `get_dict()` (used by the integration to snapshot the session)
work against the mock.
(AI) Add __init__ lifecycle tests
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
c8437d42e7
Covers `async_setup_entry` end-to-end against mocked `ComwattClient`:
the entry reaches `LOADED`, `authenticate()` is called with the stored
credentials, and `hass.data[DOMAIN]['cookies']` is populated.

`test_unload_entry_cleans_up` is marked strict-xfail against finding
C5: `async_unload_entry` pops `entry.entry_id`, but setup only writes
to the shared `"cookies"` key, so unload raises `KeyError` today. The
xfail will flip to xpass (and must be removed) once C5 is fixed.
mat force-pushed test/init from c8437d42e7
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 2s
Validate / validate-hassfest (pull_request) Failing after 2s
to df721a02d2
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 3s
Validate / validate-hassfest (pull_request) Failing after 2s
2026-04-24 12:25:27 +00:00
Compare
mat changed title from (AI) Add __init__ lifecycle tests to Add __init__ lifecycle tests 2026-04-24 12:25:50 +00:00
mat force-pushed test/init from df721a02d2
Some checks failed
Validate / validate-hacs (push) Failing after 2s
Validate / validate-hassfest (push) Failing after 2s
Validate / validate-hacs (pull_request) Failing after 3s
Validate / validate-hassfest (pull_request) Failing after 2s
to 59f18797e6
All checks were successful
Validate / validate-hacs (push) Has been skipped
Validate / validate-hassfest (push) Has been skipped
Validate / validate-hacs (pull_request) Has been skipped
Validate / validate-hassfest (pull_request) Has been skipped
2026-04-24 12:36:53 +00:00
Compare
mat merged commit 22519e00b0 into main 2026-04-24 12:38:37 +00:00
mat deleted branch test/init 2026-04-24 12:38:37 +00:00
mat referenced this pull request from a commit 2026-04-24 12:38:37 +00:00
mat referenced this pull request from a commit 2026-04-24 14:26:33 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!5
No description provided.