pytest-homeassistant-custom-component is an experimental pytest plugin designed to facilitate testing of Home Assistant custom components. It automatically extracts test plugins and provides fixtures tailored for Home Assistant's architecture. The current version is 0.13.322, with a frequent release cadence that closely tracks Home Assistant core versions.
pip install pytest-homeassistant-custom-componentNo compatibility data collected yet for this library.
This quickstart demonstrates how to write a basic asynchronous pytest test using the `hass` fixture provided by the plugin. Save this code as `test_example.py` in your project's `tests/` directory and run `pytest` from your terminal. For actual custom component testing, you'd typically use `enable_custom_integration` and interact with Home Assistant's state machine, services, and entities.
Refer to the plugin's release notes on GitHub for the supported Home Assistant core version for your `pytest-homeassistant-custom-component` version. Update the plugin to the latest version if you update Home Assistant core.
Verify your Python environment's version (`python --version`) and ensure it meets the minimum requirement. Use tools like `pyenv` or `conda` to manage Python versions if needed.
Always define your test functions as `async def test_my_feature(...)` when using `pytest-homeassistant-custom-component` fixtures and ensure all async calls are `await`-ed.
In your test functions, use `await enable_custom_integration("your_integration_domain")` before attempting to set up or interact with your custom component.