2018-05-01 17:35:23 +00:00
|
|
|
"""Fixtures for component testing."""
|
2022-03-14 08:50:55 +00:00
|
|
|
from collections.abc import Generator
|
|
|
|
from unittest.mock import AsyncMock, patch
|
2021-01-01 21:31:56 +00:00
|
|
|
|
2018-05-01 17:35:23 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-08-12 14:08:33 +00:00
|
|
|
|
2021-04-25 18:16:38 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
|
|
def patch_zeroconf_multiple_catcher():
|
|
|
|
"""Patch zeroconf wrapper that detects if multiple instances are used."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zeroconf.install_multiple_zeroconf_catcher",
|
|
|
|
side_effect=lambda zc: None,
|
|
|
|
):
|
|
|
|
yield
|
2020-08-12 14:08:33 +00:00
|
|
|
|
2018-11-21 19:55:21 +00:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def prevent_io():
|
|
|
|
"""Fixture to prevent certain I/O from happening."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
2020-08-27 11:56:20 +00:00
|
|
|
"homeassistant.components.http.ban.async_load_ip_bans_config",
|
|
|
|
return_value=[],
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-11-21 19:55:21 +00:00
|
|
|
yield
|
2022-03-14 08:50:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def entity_registry_enabled_by_default() -> Generator[AsyncMock, None, None]:
|
|
|
|
"""Test fixture that ensures all entities are enabled in the registry."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
|
|
|
|
return_value=True,
|
|
|
|
) as mock_entity_registry_enabled_by_default:
|
|
|
|
yield mock_entity_registry_enabled_by_default
|