From 35a4b685b3c427e291a8b7814d182d84725f1df1 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 12 Nov 2025 19:01:21 +0100 Subject: [PATCH] Fix steamist tests opening sockets (#156467) --- tests/components/steamist/conftest.py | 16 ++++++++++++++++ tests/components/steamist/test_init.py | 2 ++ tests/components/steamist/test_sensor.py | 4 ++++ tests/components/steamist/test_switch.py | 4 ++++ 4 files changed, 26 insertions(+) create mode 100644 tests/components/steamist/conftest.py diff --git a/tests/components/steamist/conftest.py b/tests/components/steamist/conftest.py new file mode 100644 index 000000000000..a99b977bf934 --- /dev/null +++ b/tests/components/steamist/conftest.py @@ -0,0 +1,16 @@ +"""Test fixtures for the Steamist integration.""" + +from collections.abc import Generator +from unittest.mock import AsyncMock, MagicMock, patch + +import pytest + + +@pytest.fixture +def mock_aio_discovery() -> Generator[MagicMock]: + """Mock AIODiscovery30303.""" + with patch( + "homeassistant.components.steamist.discovery.AIODiscovery30303" + ) as mock_aio_discovery: + mock_aio_discovery.return_value.async_scan = AsyncMock() + yield mock_aio_discovery diff --git a/tests/components/steamist/test_init.py b/tests/components/steamist/test_init.py index 0ef8edca9a83..aa0fc891052f 100644 --- a/tests/components/steamist/test_init.py +++ b/tests/components/steamist/test_init.py @@ -42,6 +42,7 @@ def mock_single_broadcast_address(): yield +@pytest.mark.usefixtures("mock_aio_discovery") async def test_config_entry_reload(hass: HomeAssistant) -> None: """Test that a config entry can be reloaded.""" _, config_entry = await _async_setup_entry_with_status( @@ -52,6 +53,7 @@ async def test_config_entry_reload(hass: HomeAssistant) -> None: assert config_entry.state is ConfigEntryState.NOT_LOADED +@pytest.mark.usefixtures("mock_aio_discovery") async def test_config_entry_retry_later(hass: HomeAssistant) -> None: """Test that a config entry retry on connection error.""" config_entry = MockConfigEntry( diff --git a/tests/components/steamist/test_sensor.py b/tests/components/steamist/test_sensor.py index 8731e803e0b0..9242587c179d 100644 --- a/tests/components/steamist/test_sensor.py +++ b/tests/components/steamist/test_sensor.py @@ -2,6 +2,8 @@ from __future__ import annotations +import pytest + from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime from homeassistant.core import HomeAssistant @@ -12,6 +14,7 @@ from . import ( ) +@pytest.mark.usefixtures("mock_aio_discovery") async def test_steam_active(hass: HomeAssistant) -> None: """Test that the sensors are setup with the expected values when steam is active.""" await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE) @@ -23,6 +26,7 @@ async def test_steam_active(hass: HomeAssistant) -> None: assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES +@pytest.mark.usefixtures("mock_aio_discovery") async def test_steam_inactive(hass: HomeAssistant) -> None: """Test that the sensors are setup with the expected values when steam is not active.""" await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE) diff --git a/tests/components/steamist/test_switch.py b/tests/components/steamist/test_switch.py index cd62c18590a0..ca70c00b20da 100644 --- a/tests/components/steamist/test_switch.py +++ b/tests/components/steamist/test_switch.py @@ -5,6 +5,8 @@ from __future__ import annotations from datetime import timedelta from unittest.mock import AsyncMock +import pytest + from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant @@ -19,6 +21,7 @@ from . import ( from tests.common import async_fire_time_changed +@pytest.mark.usefixtures("mock_aio_discovery") async def test_steam_active(hass: HomeAssistant) -> None: """Test that the switches are setup with the expected values when steam is active.""" client, _ = await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE) @@ -38,6 +41,7 @@ async def test_steam_active(hass: HomeAssistant) -> None: assert hass.states.get("switch.steam_active").state == STATE_OFF +@pytest.mark.usefixtures("mock_aio_discovery") async def test_steam_inactive(hass: HomeAssistant) -> None: """Test that the switches are setup with the expected values when steam is not active.""" client, _ = await _async_setup_entry_with_status(