Package to automatically extract testing plugins from Home Assistant for custom component testing. The goal is to provide the same functionality as the tests in home-assistant/core. pytest-homeassistant-custom-component is updated daily according to the latest homeassistant release including beta.
hassfrom tests.common import MockConfigEntryfrom pytest_homeassistant_custom_component.common import MockConfigEntrycustom_components folder, a custom_components/__init__.py file or changes to sys.path may be required.enable_custom_integrations fixture is required (versions >=2021.6.0b0)recorder_mock, need to be initialized before enable_custom_integrations. See https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/issues/132.asyncio_mode = auto config, see https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/issues/129 and https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/issues/247.load_fixture, the files need to be in a fixtures folder colocated with the tests. For example, a test in test_sensor.py can load data from some_data.json using load_fixture from this structure:tests/
fixtures/
some_data.json
test_sensor.py
snapshot fixture to conftest.py to make sure the snapshots are loaded from snapshot folder colocated with the tests. from pytest_homeassistant_custom_component.syrupy import HomeAssistantSnapshotExtension
from syrupy.assertion import SnapshotAssertion
@pytest.fixture
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion:
"""Return snapshot assertion fixture with the Home Assistant extension."""
return snapshot.use_extension(HomeAssistantSnapshotExtension)
simple_integration in this repository.This repository is set up to be nearly fully automatic.
ha_version, pytest_homeassistant_custom_component.const, and in the README above.pytest_homeassistant_custom_component files. CI testing will automatically generate the new files.This package was inspired by pytest-homeassistant by @boralyl, but is intended to more closely and automatically track the home-assistant/core library.
$ claude mcp add pytest-homeassistant-custom-component \
-- python -m otcore.mcp_server <graph>