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