You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
A pytest plugin for use with Home Assistant custom components.
This pytest plugin provides several pytest fixtures and utils to make testing
Home Assistant custom components easier.
The plugin allows you to use a subset of fixtures and helpers from the
Home Assistant test code to allow you to test your own custom components.
Features
Fixtures
hass - Used to mock a hass instance. This is primarily useful in testing your
config_flow code. Examples of it's usage can be found in the Home Assistant
tests.
aioclient_mock - Used to mock responses from homeassistant.helpers.aiohttp_client.async_get_clientsession
in your test code.
You can find example usage of both of these fixtures in the Home Assistant tests directory.
Helpers
pytest_homeassistant.async_mock - Contains all mock methods that can handle
async calls.
frompytest_homeassistant.async_mockimportAsyncMockfromcustom_components.steam_wishlistimportsensor_managerasyncdeftest_sensormanager_async_register_component(
hass, coordinator_mock
):
"""Test that we add listeners and referesh data if all platforms were registered."""manager=sensor_manager.SensorManager(hass, url="https://fake.com")
mock_async_add_entities=AsyncMock()
awaitmanager.async_register_component("sensor", mock_async_add_entities)
assertmock_async_add_entities.calledisTrue
Requirements
homeassistant
Installation
You can install "pytest-homeassistant" via pip from PyPI:
$ pip install pytest-homeassistant
Contributing
Contributions are very welcome. I only incldued fixtures and test helpers that
were useful to me when testing my custom components. If there are others that would
be useful to you, pull requests are welcome!
License
Distributed under the terms of the MIT license, "pytest-homeassistant" is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
About
A pytest plugin for use with homeassistant custom components.