Handle integration with missing dependencies (#122386)

This commit is contained in:
Erik Montnemery 2024-07-22 15:41:55 +02:00 committed by GitHub
parent 7ec41275d5
commit c73e7ae178
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -906,7 +906,13 @@ async def _async_resolve_domains_to_setup(
await asyncio.gather(*resolve_dependencies_tasks)
for itg in integrations_to_process:
for dep in itg.all_dependencies:
try:
all_deps = itg.all_dependencies
except RuntimeError:
# Integration.all_dependencies raises RuntimeError if
# dependencies could not be resolved
continue
for dep in all_deps:
if dep in domains_to_setup:
continue
domains_to_setup.add(dep)

View File

@ -1329,6 +1329,34 @@ async def test_bootstrap_dependencies(
)
@pytest.mark.parametrize("load_registries", [False])
async def test_bootstrap_dependency_not_found(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test setup when an integration has missing dependencies."""
mock_integration(
hass,
MockModule("good_integration", dependencies=[]),
)
# Simulate an integration with missing dependencies. While a core integration
# can't have missing dependencies thanks to checks by hassfest, there's no such
# guarantee for custom integrations.
mock_integration(
hass,
MockModule("bad_integration", dependencies=["hahaha_crash_and_burn"]),
)
assert await bootstrap.async_from_config_dict(
{"good_integration": {}, "bad_integration": {}}, hass
)
assert "good_integration" in hass.config.components
assert "bad_integration" not in hass.config.components
assert "Unable to resolve dependencies for bad_integration" in caplog.text
async def test_pre_import_no_requirements(hass: HomeAssistant) -> None:
"""Test pre-imported and do not have any requirements."""
pre_imports = [