From 5d1dfab048eddb2b7d81b772a8cf21759c86ab2d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Aug 2026 17:33:41 +0000 Subject: [PATCH] Fix DHCP/scapy socket block in test_init_setup_entry.py 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 Claude-Session: https://claude.ai/code/session_01KmCpFs3Y4KhAjap7dSMNco --- tests/python/setup/test_init_setup_entry.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/python/setup/test_init_setup_entry.py b/tests/python/setup/test_init_setup_entry.py index 263da8e..cfc0257 100644 --- a/tests/python/setup/test_init_setup_entry.py +++ b/tests/python/setup/test_init_setup_entry.py @@ -8,6 +8,8 @@ from __future__ import annotations +from unittest.mock import AsyncMock + import pytest from custom_components.digital_frames.const import DOMAIN, KIND_SCENES_HUB @@ -19,6 +21,16 @@ def _no_real_network(monkeypatch): "custom_components.digital_frames.coordinator.async_get_clientsession", lambda hass: _FakeSession(), ) + # manifest.json declares `dhcp` as a dependency, so every hass fixture in + # this file loads HA core's dhcp component too. That component's own + # EVENT_HOMEASSISTANT_STARTED listener calls both aiodhcpwatcher.async_init() + # and (via DHCPWatcher.async_start) aiodhcpwatcher.async_start(), each of + # which opens a real AF_NETLINK socket via scapy -- irrelevant to what + # this file tests, but fatal under pytest-socket's sandbox (and a real + # network syscall otherwise). Stub both out so firing that event here + # only exercises this integration's own listener. + monkeypatch.setattr("aiodhcpwatcher.async_init", AsyncMock()) + monkeypatch.setattr("aiodhcpwatcher.async_start", AsyncMock(return_value=lambda: None)) class _FakeResponse: