From fdfc2f48459d6264632fcc9f0997fead0e4d4108 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Fri, 20 Mar 2026 17:43:42 +0100 Subject: [PATCH] Fix FRITZ!Box Tools "the test opens sockets" issue (#165596) --- tests/components/fritz/test_config_flow.py | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/components/fritz/test_config_flow.py b/tests/components/fritz/test_config_flow.py index c8057a09d1b9..2da33a1e2294 100644 --- a/tests/components/fritz/test_config_flow.py +++ b/tests/components/fritz/test_config_flow.py @@ -658,9 +658,15 @@ async def test_ssdp_already_in_progress_host( hass: HomeAssistant, fc_class_mock ) -> None: """Test starting a flow from discovery twice.""" - with patch( - "homeassistant.components.fritz.config_flow.FritzConnection", - side_effect=fc_class_mock, + with ( + patch( + "homeassistant.components.fritz.config_flow.FritzConnection", + side_effect=fc_class_mock, + ), + patch( + "homeassistant.components.fritz.config_flow.socket.gethostbyname", + return_value=MOCK_IPS["fritz.box"], + ), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA @@ -689,6 +695,10 @@ async def test_ssdp(hass: HomeAssistant, fc_class_mock) -> None: "homeassistant.components.fritz.coordinator.FritzBoxTools._update_device_info", return_value=MOCK_FIRMWARE_INFO, ), + patch( + "homeassistant.components.fritz.config_flow.socket.gethostbyname", + return_value=MOCK_IPS["fritz.box"], + ), patch("homeassistant.components.fritz.async_setup_entry") as mock_setup_entry, patch("requests.get") as mock_request_get, patch("requests.post") as mock_request_post, @@ -722,9 +732,15 @@ async def test_ssdp(hass: HomeAssistant, fc_class_mock) -> None: async def test_ssdp_exception(hass: HomeAssistant) -> None: """Test starting a flow from discovery but no device found.""" - with patch( - "homeassistant.components.fritz.config_flow.FritzConnection", - side_effect=FritzConnectionException, + with ( + patch( + "homeassistant.components.fritz.config_flow.FritzConnection", + side_effect=FritzConnectionException, + ), + patch( + "homeassistant.components.fritz.config_flow.socket.gethostbyname", + return_value=MOCK_IPS["fritz.box"], + ), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA