Skip to content

Commit 26bb301

Browse files
authored
Fix lifx tests opening sockets (home-assistant#156460)
1 parent 4159e48 commit 26bb301

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

tests/components/lifx/test_config_flow.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Tests for the lifx integration config flow."""
22

3+
from collections.abc import Generator
34
from ipaddress import ip_address
45
import socket
56
from typing import Any
6-
from unittest.mock import patch
7+
from unittest.mock import AsyncMock, patch
78

89
import pytest
910

@@ -44,6 +45,15 @@
4445
from tests.common import MockConfigEntry
4546

4647

48+
@pytest.fixture(autouse=True)
49+
def mock_setup_entry() -> Generator[AsyncMock]:
50+
"""Override async_setup_entry."""
51+
with patch(
52+
"homeassistant.components.lifx.async_setup_entry", return_value=True
53+
) as mock_setup_entry:
54+
yield mock_setup_entry
55+
56+
4757
async def test_discovery(hass: HomeAssistant) -> None:
4858
"""Test setting up discovery."""
4959
with _patch_discovery(), _patch_config_flow_try_connect():
@@ -591,6 +601,7 @@ async def test_refuse_relays(hass: HomeAssistant) -> None:
591601
assert result2["errors"] == {"base": "cannot_connect"}
592602

593603

604+
@pytest.mark.parametrize("mock_setup_entry", [None]) # Disable the autouse fixture
594605
async def test_suggested_area(
595606
hass: HomeAssistant,
596607
area_registry: ar.AreaRegistry,

tests/components/lifx/test_light.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,9 +1619,10 @@ async def test_transitions_brightness_only(hass: HomeAssistant) -> None:
16191619
bulb.get_color.reset_mock()
16201620

16211621
# Ensure we force an update after the transition
1622-
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
1623-
await hass.async_block_till_done()
1624-
assert len(bulb.get_color.calls) == 2
1622+
with _patch_discovery(device=bulb):
1623+
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
1624+
await hass.async_block_till_done()
1625+
assert len(bulb.get_color.calls) == 2
16251626

16261627

16271628
async def test_transitions_color_bulb(hass: HomeAssistant) -> None:
@@ -1714,9 +1715,10 @@ async def test_transitions_color_bulb(hass: HomeAssistant) -> None:
17141715
bulb.get_color.reset_mock()
17151716

17161717
# Ensure we force an update after the transition
1717-
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
1718-
await hass.async_block_till_done()
1719-
assert len(bulb.get_color.calls) == 2
1718+
with _patch_discovery(device=bulb):
1719+
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=5))
1720+
await hass.async_block_till_done()
1721+
assert len(bulb.get_color.calls) == 2
17201722

17211723
bulb.set_power.reset_mock()
17221724
bulb.set_color.reset_mock()

0 commit comments

Comments
 (0)