Ensure smilight fixtures select correct platform for tests (#124305)
* Fix return type hint for setup_integration * Ensure platform fixture selects tested platformpull/124933/head
parent
a8b55a16fd
commit
5e93394ae7
|
@ -1,13 +1,14 @@
|
|||
"""Common fixtures for the SMLIGHT Zigbee tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from pysmlight.web import Info, Sensors
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.smlight import PLATFORMS
|
||||
from homeassistant.components.smlight.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
@ -31,6 +32,19 @@ def mock_config_entry() -> MockConfigEntry:
|
|||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platforms() -> list[Platform]:
|
||||
"""Platforms, which should be loaded during the test."""
|
||||
return PLATFORMS
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def mock_patch_platforms(platforms: list[str]) -> AsyncGenerator[None, None]:
|
||||
"""Fixture to set up platforms for tests."""
|
||||
with patch(f"homeassistant.components.{DOMAIN}.PLATFORMS", platforms):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||
"""Override async_setup_entry."""
|
||||
|
@ -64,7 +78,10 @@ def mock_smlight_client(request: pytest.FixtureRequest) -> Generator[MagicMock]:
|
|||
yield api
|
||||
|
||||
|
||||
async def setup_integration(hass: HomeAssistant, mock_config_entry: MockConfigEntry):
|
||||
async def setup_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the integration."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ pytestmark = [
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def platforms() -> Platform | list[Platform]:
|
||||
def platforms() -> list[Platform]:
|
||||
"""Platforms, which should be loaded during the test."""
|
||||
return Platform.SENSOR
|
||||
return [Platform.SENSOR]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
|
|
Loading…
Reference in New Issue