Skip to content

Commit

Permalink
Ensure smilight fixtures select correct platform for tests (#124305)
Browse files Browse the repository at this point in the history
* Fix return type hint for setup_integration

* Ensure platform fixture selects tested platform
  • Loading branch information
tl-sl authored Aug 30, 2024
1 parent a8b55a1 commit 5e93394
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions tests/components/smlight/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/components/smlight/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@


@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")
Expand Down

0 comments on commit 5e93394

Please sign in to comment.