From 1576d095c8b5be67bd92b12b186e3c9035acfe96 Mon Sep 17 00:00:00 2001 From: Marc Billow Date: Tue, 21 Jul 2026 02:05:57 +0000 Subject: [PATCH] ci: run pytest in CI; complete dev requirements; unblock socket test The suite was never run in CI (only hassfest/HACS), and requirements-dev listed only pytest + smartthings-local while conftest.py needs the full Home Assistant test harness. - requirements-dev.txt: add pytest-homeassistant-custom-component (pulls in home-assistant + pytest + pytest-socket) and the integration's runtime deps (cbor2, pyOpenSSL, cryptography) needed to import it. - .github/workflows/validate.yml: add a Pytest job on Python 3.14 (current Home Assistant's floor) that installs requirements-dev and runs the suite. - test_config_flow.py: the UDP liveness-sweep test needs real loopback sockets, which the HA harness blocks by default; take the pytest-socket socket_enabled fixture so it runs instead of erroring. Full suite: 249 passed. --- .github/workflows/validate.yml | 20 ++++++++++++++++++++ requirements-dev.txt | 11 ++++++++++- tests/localthings/test_config_flow.py | 6 +++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index b906e99..8993a62 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -35,3 +35,23 @@ jobs: uses: hacs/action@main with: category: integration + + tests: + name: Pytest + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.14" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + + - name: Run tests + run: pytest tests/ -q diff --git a/requirements-dev.txt b/requirements-dev.txt index f410cb4..e5a378b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,11 @@ -pytest>=8.0 +# Test harness — pulls in home-assistant, pytest, and pytest-socket at the +# matching versions. Current Home Assistant requires Python >= 3.14; pip will +# resolve the newest home-assistant your interpreter supports. +pytest-homeassistant-custom-component>=0.13.316 + +# Integration runtime deps, needed to import the component under test +# (also declared in custom_components/localthings/manifest.json). smartthings-local>=0.1.0 +cbor2>=5.4.6 +pyOpenSSL>=23.0 +cryptography>=41.0 diff --git a/tests/localthings/test_config_flow.py b/tests/localthings/test_config_flow.py index 0556511..294e780 100644 --- a/tests/localthings/test_config_flow.py +++ b/tests/localthings/test_config_flow.py @@ -67,7 +67,7 @@ def test_order_candidates_prefers_known_ports() -> None: assert _order_candidates([49153]) == [49153] -def test_find_live_ports_detects_silent_port() -> None: +def test_find_live_ports_detects_silent_port(socket_enabled) -> None: """The UDP liveness sweep flags a bound-but-silent port as live and drops ports that refuse with ICMP port-unreachable. @@ -75,6 +75,10 @@ def test_find_live_ports_detects_silent_port() -> None: stays silent (open|filtered), like the dishwasher in issue #13 on 49153. Two sibling ports are reserved then closed so loopback refuses datagrams to them, standing in for the closed ports the scan should discard. + + `socket_enabled` lifts pytest-socket's default block (the HA test harness + disables real sockets); this test genuinely needs loopback UDP to exercise + the ICMP-unreachable path. """ import socket