From 26bb301cc05b606b75e52fd94e78f95deed07abf Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 12 Nov 2025 20:51:54 +0100 Subject: [PATCH] Fix lifx tests opening sockets (#156460) --- tests/components/lifx/test_config_flow.py | 13 ++++++++++++- tests/components/lifx/test_light.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/components/lifx/test_config_flow.py b/tests/components/lifx/test_config_flow.py index aecc71b07e8..dbea7c437f9 100644 --- a/tests/components/lifx/test_config_flow.py +++ b/tests/components/lifx/test_config_flow.py @@ -1,9 +1,10 @@ """Tests for the lifx integration config flow.""" +from collections.abc import Generator from ipaddress import ip_address import socket from typing import Any -from unittest.mock import patch +from unittest.mock import AsyncMock, patch import pytest @@ -44,6 +45,15 @@ from . import ( from tests.common import MockConfigEntry +@pytest.fixture(autouse=True) +def mock_setup_entry() -> Generator[AsyncMock]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.lifx.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry + + async def test_discovery(hass: HomeAssistant) -> None: """Test setting up discovery.""" with _patch_discovery(), _patch_config_flow_try_connect(): @@ -591,6 +601,7 @@ async def test_refuse_relays(hass: HomeAssistant) -> None: assert result2["errors"] == {"base": "cannot_connect"} +@pytest.mark.parametrize("mock_setup_entry", [None]) # Disable the autouse fixture async def test_suggested_area( hass: HomeAssistant, area_registry: ar.AreaRegistry, diff --git a/tests/components/lifx/test_light.py b/tests/components/lifx/test_light.py index dff43bc21b6..636ec87dee4 100644 --- a/tests/components/lifx/test_light.py +++ b/tests/components/lifx/test_light.py @@ -1619,9 +1619,10 @@ async def test_transitions_brightness_only(hass: HomeAssistant) -> None: bulb.get_color.reset_mock() # Ensure we force an update after the transition - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5)) - await hass.async_block_till_done() - assert len(bulb.get_color.calls) == 2 + with _patch_discovery(device=bulb): + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5)) + await hass.async_block_till_done() + assert len(bulb.get_color.calls) == 2 async def test_transitions_color_bulb(hass: HomeAssistant) -> None: @@ -1714,9 +1715,10 @@ async def test_transitions_color_bulb(hass: HomeAssistant) -> None: bulb.get_color.reset_mock() # Ensure we force an update after the transition - async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5)) - await hass.async_block_till_done() - assert len(bulb.get_color.calls) == 2 + with _patch_discovery(device=bulb): + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5)) + await hass.async_block_till_done() + assert len(bulb.get_color.calls) == 2 bulb.set_power.reset_mock() bulb.set_color.reset_mock()