Skip to content

Fix pytest-socket SocketBlockedError in test_init_setup_entry.py - #21

Merged
dsackr merged 2 commits into
mainfrom
fix/dhcp-test-socket-block
Aug 12, 2026
Merged

dsackr merged 2 commits into
mainfrom
fix/dhcp-test-socket-block

Conversation

@dsackr

@dsackr dsackr commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • docs/TEST_LEDGER.md has shown backend-pytest red on main for several days now, always on the same single test: tests/python/setup/test_init_setup_entry.py::test_late_bound_tracker_watch_does_not_violate_thread_safety (pytest_socket.SocketBlockedError).
  • Root cause: manifest.json declares dhcp as a dependency, so every hass fixture in this test file also loads HA core's dhcp component. That component's own EVENT_HOMEASSISTANT_STARTED listener calls aiodhcpwatcher.async_init() and (via DHCPWatcher.async_start) aiodhcpwatcher.async_start(), both of which open a real AF_NETLINK socket via scapy — fatal under pytest-socket's sandbox, and unrelated to what this test file actually verifies (this integration's own late-bound tracker-watch listener).
  • Fix: stub both aiodhcpwatcher entry points in the file's existing _no_real_network autouse fixture, so firing EVENT_HOMEASSISTANT_STARTED in tests only exercises this integration's own listener, not HA core's real DHCP watcher.

Pure test-infrastructure fix — no product code changed, no behavior change, so no KPF update needed per AGENTS.md.

Note: after this fix, the suite still shows 2 unrelated failures (test_built_in_skills_seeded_on_first_load, test_built_ins_not_reseeded_after_user_deletes_one — a hardcoded built-in-skill count gone stale after the new "Daily Newspaper" skill was added). Out of scope for this PR; left untouched.

Test plan

  • tests/python/setup/test_init_setup_entry.py — 9 passed, 0 errors (was: 1 error)
  • Full suite — 548 passed, 2 failed (pre-existing, unrelated), 0 errors (was: 1 error)

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01KmCpFs3Y4KhAjap7dSMNco


Generated by Claude Code

manifest.json's dhcp dependency means every hass fixture in this file
loads HA core's dhcp component. Its EVENT_HOMEASSISTANT_STARTED listener
calls aiodhcpwatcher.async_init/async_start, which open a real AF_NETLINK
socket via scapy -- irrelevant to what this file tests, and fatal under
pytest-socket's sandbox (this is the pre-existing main-branch failure
tracked across many CI runs: test_late_bound_tracker_watch_does_not_violate_thread_safety).
Stub both calls so firing that event here only exercises this
integration's own tracker-watch listener.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KmCpFs3Y4KhAjap7dSMNco

dsackr commented Aug 7, 2026

Copy link
Copy Markdown
Owner Author

CI confirms the fix: 2 failed, 548 passed — the DHCP/scapy SocketBlockedError is gone (0 errors, matching local verification). The 2 remaining failures are the pre-existing, unrelated test_built_in_skills_seeded_on_first_load / test_built_ins_not_reseeded_after_user_deletes_one regression from the "Daily Newspaper" skill addition (already noted in the PR description) — out of scope here. This PR is ready for review/merge whenever convenient.


Generated by Claude Code

@dsackr
dsackr merged commit 9de6046 into main Aug 12, 2026
3 checks passed
@dsackr
dsackr deleted the fix/dhcp-test-socket-block branch August 12, 2026 01:53
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.

2 participants