Skip to content

Bootstrap pytest-homeassistant-custom-component harness + CI workflow #1257

@frenckatron

Description

@frenckatron

Why This Matters

The repo has no tests/ directory, no pytest dependency, and no test job in .github/workflows/ (only ruff, pylint, hassfest, hacs). That means every refactor of the importlib-rglob discovery in services.py:289-301, repairs.py:276-286, and util.py:235-251 is currently validated by hand inside a running HA. PHACC plugs straight into HA's own test fixtures, so the only cost is the initial scaffolding — and once it exists, every subsequent sub-issue is a 30-line drop-in. This is the single foundational lever for the whole initiative.

Approach

Add pytest-homeassistant-custom-component to [tool.uv].dev-dependencies in pyproject.toml. Create tests/__init__.py, tests/conftest.py with an enable_custom_integrations autouse fixture, and tests/test_init.py containing one smoke test that uses MockConfigEntry(domain="spook"), calls hass.config_entries.async_setup, and asserts the entry reaches ConfigEntryState.LOADED. Add [tool.pytest.ini_options] to pyproject.toml with asyncio_mode = "auto". Create .github/workflows/test.yaml mirroring the style of ruff.yaml/pylint.yaml (uv-based, Python 3.13, uv run pytest). Pin the PHACC version to match the homeassistant>=2025.2.0 floor declared in pyproject.toml.

Acceptance Criteria

  • uv run pytest runs locally and passes
  • tests/conftest.py exposes the enable_custom_integrations fixture
  • At least one smoke test loads the Spook config entry end-to-end
  • A test.yaml GitHub workflow runs on PR/push and is required for merge
  • pyproject.toml documents the PHACC pin alongside the HA version floor

Risks & Caveats

PHACC's HA-version compatibility is strict — a bump of homeassistant>=2025.2.0 will sometimes force a PHACC bump and a coordinated set of test fixes. The symlink dance in __init__.py:36-79 will probably trip up the smoke test because link_sub_integrations writes into hass.config.config_dir; mitigate with a tmp_path-rooted config or by mocking link_sub_integrations in the smoke test.

Scores

  • Impact: █████████░ 9/10
  • Difficulty: ████░░░░░░ 4/10
  • Short-Term ROI: ████████░░ 8/10
  • Long-Term Value: ██████████ 10/10

Priority

Immediate

Dependencies

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions