mirror of
https://github.com/home-assistant/core.git
synced 2025-09-12 16:21:35 +02:00
Add platform patching in init_integration
fixture in copilot-instructions.md (#151173)
This commit is contained in:
19
.github/copilot-instructions.md
vendored
19
.github/copilot-instructions.md
vendored
@@ -1073,7 +1073,11 @@ async def test_flow_connection_error(hass, mock_api_error):
|
|||||||
|
|
||||||
### Entity Testing Patterns
|
### Entity Testing Patterns
|
||||||
```python
|
```python
|
||||||
@pytest.mark.parametrize("init_integration", [Platform.SENSOR], indirect=True)
|
@pytest.fixture
|
||||||
|
def platforms() -> list[Platform]:
|
||||||
|
"""Overridden fixture to specify platforms to test."""
|
||||||
|
return [Platform.SENSOR] # Or another specific platform as needed.
|
||||||
|
|
||||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration")
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration")
|
||||||
async def test_entities(
|
async def test_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@@ -1120,16 +1124,25 @@ def mock_device_api() -> Generator[MagicMock]:
|
|||||||
)
|
)
|
||||||
yield api
|
yield api
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def platforms() -> list[Platform]:
|
||||||
|
"""Fixture to specify platforms to test."""
|
||||||
|
return PLATFORMS
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def init_integration(
|
async def init_integration(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
mock_device_api: MagicMock,
|
mock_device_api: MagicMock,
|
||||||
|
platforms: list[Platform],
|
||||||
) -> MockConfigEntry:
|
) -> MockConfigEntry:
|
||||||
"""Set up the integration for testing."""
|
"""Set up the integration for testing."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
mock_config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
with patch("homeassistant.components.my_integration.PLATFORMS", platforms):
|
||||||
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return mock_config_entry
|
return mock_config_entry
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user