Fix flaky test in acmeda (#135846)

This commit is contained in:
epenet 2025-01-17 19:08:32 +01:00 committed by GitHub
parent 54e4e8a7bb
commit 14f3868c26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 13 deletions

View File

@ -1,5 +1,8 @@
"""Define fixtures available for all Acmeda tests.""" """Define fixtures available for all Acmeda tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest import pytest
from homeassistant.components.acmeda.const import DOMAIN from homeassistant.components.acmeda.const import DOMAIN
@ -18,3 +21,10 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
) )
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
return mock_config_entry return mock_config_entry
@pytest.fixture
def mock_hub_run() -> Generator[AsyncMock]:
"""Mock the hub run method."""
with patch("homeassistant.components.acmeda.hub.aiopulse.Hub.run") as mock_run:
yield mock_run

View File

@ -28,13 +28,6 @@ def mock_hub_discover():
yield mock_discover yield mock_discover
@pytest.fixture
def mock_hub_run():
"""Mock the hub run method."""
with patch("aiopulse.Hub.run") as mock_run:
yield mock_run
async def async_generator(items): async def async_generator(items):
"""Async yields items provided in a list.""" """Async yields items provided in a list."""
for item in items: for item in items:
@ -56,9 +49,8 @@ async def test_show_form_no_hubs(hass: HomeAssistant, mock_hub_discover) -> None
assert len(mock_hub_discover.mock_calls) == 1 assert len(mock_hub_discover.mock_calls) == 1
async def test_show_form_one_hub( @pytest.mark.usesfixtures("mock_hub_run")
hass: HomeAssistant, mock_hub_discover, mock_hub_run async def test_show_form_one_hub(hass: HomeAssistant, mock_hub_discover) -> None:
) -> None:
"""Test that a config is created when one hub discovered.""" """Test that a config is created when one hub discovered."""
dummy_hub_1 = aiopulse.Hub(DUMMY_HOST1) dummy_hub_1 = aiopulse.Hub(DUMMY_HOST1)
@ -102,9 +94,8 @@ async def test_show_form_two_hubs(hass: HomeAssistant, mock_hub_discover) -> Non
assert len(mock_hub_discover.mock_calls) == 1 assert len(mock_hub_discover.mock_calls) == 1
async def test_create_second_entry( @pytest.mark.usesfixtures("mock_hub_run")
hass: HomeAssistant, mock_hub_run, mock_hub_discover async def test_create_second_entry(hass: HomeAssistant, mock_hub_discover) -> None:
) -> None:
"""Test that a config is created when a second hub is discovered.""" """Test that a config is created when a second hub is discovered."""
dummy_hub_1 = aiopulse.Hub(DUMMY_HOST1) dummy_hub_1 = aiopulse.Hub(DUMMY_HOST1)

View File

@ -1,5 +1,7 @@
"""Define tests for the Acmeda config flow.""" """Define tests for the Acmeda config flow."""
import pytest
from homeassistant.components.acmeda.const import DOMAIN from homeassistant.components.acmeda.const import DOMAIN
from homeassistant.components.cover import DOMAIN as COVER_DOMAIN from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -8,6 +10,7 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@pytest.mark.usesfixtures("mock_hub_run")
async def test_cover_id_migration( async def test_cover_id_migration(
hass: HomeAssistant, hass: HomeAssistant,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,

View File

@ -1,5 +1,7 @@
"""Define tests for the Acmeda config flow.""" """Define tests for the Acmeda config flow."""
import pytest
from homeassistant.components.acmeda.const import DOMAIN from homeassistant.components.acmeda.const import DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -8,6 +10,7 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@pytest.mark.usesfixtures("mock_hub_run")
async def test_sensor_id_migration( async def test_sensor_id_migration(
hass: HomeAssistant, hass: HomeAssistant,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,