mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Enable custom integrations by default in pytest-home-assistant (#187094)
This commit is contained in:
@@ -709,6 +709,12 @@ def hass_config_dir() -> str:
|
||||
return get_test_config_dir()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def custom_integrations_enabled() -> bool:
|
||||
"""Control custom integration loading."""
|
||||
return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hass(
|
||||
hass_fixture_setup: list[bool],
|
||||
@@ -717,6 +723,7 @@ async def hass(
|
||||
hass_storage: dict[str, Any],
|
||||
request: pytest.FixtureRequest,
|
||||
mock_recorder_before_hass: None,
|
||||
custom_integrations_enabled: bool,
|
||||
) -> AsyncGenerator[HomeAssistant]:
|
||||
"""Create a test instance of Home Assistant."""
|
||||
|
||||
@@ -743,6 +750,8 @@ async def hass(
|
||||
async with async_test_home_assistant(
|
||||
loop, load_registries, config_dir=hass_config_dir
|
||||
) as hass:
|
||||
if custom_integrations_enabled:
|
||||
hass.data.pop(loader.DATA_CUSTOM_COMPONENTS, None)
|
||||
orig_exception_handler = loop.get_exception_handler()
|
||||
loop.set_exception_handler(exc_handle)
|
||||
frame.async_setup(hass)
|
||||
@@ -1570,7 +1579,7 @@ def mock_async_zeroconf(mock_zeroconf: MagicMock) -> Generator[MagicMock]:
|
||||
@pytest.fixture
|
||||
def enable_custom_integrations(hass: HomeAssistant) -> None:
|
||||
"""Enable custom integrations defined in the test dir."""
|
||||
hass.data.pop(loader.DATA_CUSTOM_COMPONENTS)
|
||||
hass.data.pop(loader.DATA_CUSTOM_COMPONENTS, None)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -250,3 +250,9 @@ from pytest_homeassistant.plugins import (
|
||||
verify_cleanup as verify_cleanup,
|
||||
wait_for_stop_scripts_after_shutdown as wait_for_stop_scripts_after_shutdown,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def custom_integrations_enabled() -> bool:
|
||||
"""Control custom integration loading."""
|
||||
return False
|
||||
|
||||
@@ -12,6 +12,7 @@ from pytest_homeassistant import _paths
|
||||
from pytest_homeassistant.common import get_fixture_path
|
||||
import pytest_socket
|
||||
|
||||
from homeassistant import loader
|
||||
from homeassistant.core import HomeAssistant, async_get_hass
|
||||
from homeassistant.helpers import translation
|
||||
from homeassistant.helpers.http import HomeAssistantView
|
||||
@@ -86,6 +87,20 @@ async def test_hass_cv(hass: HomeAssistant) -> None:
|
||||
assert async_get_hass() is hass
|
||||
|
||||
|
||||
async def test_custom_integrations_disabled(hass: HomeAssistant) -> None:
|
||||
"""Test the default custom integration policy."""
|
||||
with pytest.raises(loader.IntegrationNotFound):
|
||||
await loader.async_get_integration(hass, "test_package")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("custom_integrations_enabled", [True])
|
||||
async def test_custom_integrations_enabled(hass: HomeAssistant) -> None:
|
||||
"""Load a custom integration using the enabling policy."""
|
||||
integration = await loader.async_get_integration(hass, "test_package")
|
||||
assert not integration.is_built_in
|
||||
assert await async_setup_component(hass, "test_package", {})
|
||||
|
||||
|
||||
def register_view(hass: HomeAssistant) -> None:
|
||||
"""Register a view."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user