Skip to main content

A pytest plugin for use with homeassistant custom components.

Project description

PyPI version Python versions

A pytest plugin for use with homeassistant custom components.


This pytest plugin provides several pytest fixtures and utils to make testing homeassistant custom components easier.

The plugin allows you to use a subset of fixtures and helpers from the homeassistant 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 homeassistant tests.

from custom_components.steam_wishlist import config_flow

async def test_flow_init(hass):
    """Test the initial flow."""
    result = await hass.config_entries.flow.async_init(
        config_flow.DOMAIN, context={"source": "user"}
    )

    expected = {
        "data_schema": config_flow.DATA_SCHEMA,
        "description_placeholders": None,
        "errors": {},
        "flow_id": mock.ANY,
        "handler": "steam_wishlist",
        "step_id": "user",
        "type": "form",
    }
    assert expected == result
  • 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 homeassistant tests.

Helpers

  • pytest_homeassistant.async_mock - Contains all mock methods that can handle async calls.

from pytest_homeassistant.async_mock import AsyncMock
from custom_components.steam_wishlist import sensor_manager

async def test_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="http://fake.com")
    mock_async_add_entities = AsyncMock()
    await manager.async_register_component("sensor", mock_async_add_entities)

    assert mock_async_add_entities.called is True

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-homeassistant-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distributions

pytest_homeassistant-0.1.0-py3.7.egg (24.6 kB view details)

Uploaded Source

pytest_homeassistant-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest-homeassistant-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-homeassistant-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for pytest-homeassistant-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3307ad0ab886a0f3b48c88ba87a45997611f58a637901bea55160e66be228d08
MD5 2d70308bf507ba230e461ca455a88500
BLAKE2b-256 02428dfe6a3e23dd2242923a1b8021446bfe7479776c130c042fe1d96950630b

See more details on using hashes here.

File details

Details for the file pytest_homeassistant-0.1.0-py3.7.egg.

File metadata

  • Download URL: pytest_homeassistant-0.1.0-py3.7.egg
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for pytest_homeassistant-0.1.0-py3.7.egg
Algorithm Hash digest
SHA256 80d107424920f6ca45192d42a01e0bf30eac934ede72f9fe6d7b2d7e99e133e6
MD5 45db43550da1987069ff722649f3144a
BLAKE2b-256 7d7ffaa528ec630f9bd31e093ec7ccf6e6ac9bde2e1e31cb1c624433f60df624

See more details on using hashes here.

File details

Details for the file pytest_homeassistant-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_homeassistant-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for pytest_homeassistant-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa78aafb0ac763a2c9e3be86f425fee1543d765d3c7df426c03ab891e2fadd2
MD5 230b24a426b01528c4a134cb6ae1feb3
BLAKE2b-256 9b288319ade5fc3645f9d354ecd5e1ce044b5e520066de5522ce1e392deb5c69

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page