fix(tests): close fixture drivers so no test opens a socket (#11) #12

Merged
christianmanivong merged 1 commits from fix/bugs-2026-11-02 into main 2026-11-02 08:23:34 +00:00
Owner

What

The unit tests no longer open a socket.

The driver and pppoe_driver fixtures (and test_open_sets_fc_on_success) left the driver open. When it was garbage-collected, NAPALM's NetworkDriver.__del__ called is_alive(), which resolved fritz.box and connected to port 49443, once per test. __del__ swallows the error, so it only showed as slow or flaky runs (a full run took ~5.7 s, now ~0.6 s).

  • The fixtures close the driver after the test (fc = None, so is_alive() returns without touching the network).
  • tests/conftest.py adds a session-wide guard: socket.create_connection and socket.socket.connect refuse, every attempt is recorded, and the session fails at the end if any test (including a __del__) tried to connect. Tests that patch create_connection themselves are unaffected.

No driver code changes, so no CHANGELOG entry (nothing changes for users of the driver).

Tests

Fixtures only. Red first: with only the guard in place, the session failed with 70+ recorded create_connection('fritz.box', 49443) attempts; with the fixtures closing the driver it passes. pytest (74 passed), ruff format/check, mypy, napalm-standard check and ratchet are green, coverage 81.4 % (floor 81).

Closes #11

## What The unit tests no longer open a socket. The `driver` and `pppoe_driver` fixtures (and `test_open_sets_fc_on_success`) left the driver open. When it was garbage-collected, NAPALM's `NetworkDriver.__del__` called `is_alive()`, which resolved `fritz.box` and connected to port 49443, once per test. `__del__` swallows the error, so it only showed as slow or flaky runs (a full run took ~5.7 s, now ~0.6 s). - The fixtures close the driver after the test (`fc = None`, so `is_alive()` returns without touching the network). - `tests/conftest.py` adds a session-wide guard: `socket.create_connection` and `socket.socket.connect` refuse, every attempt is recorded, and the session fails at the end if any test (including a `__del__`) tried to connect. Tests that patch `create_connection` themselves are unaffected. No driver code changes, so no CHANGELOG entry (nothing changes for users of the driver). ## Tests Fixtures only. Red first: with only the guard in place, the session failed with 70+ recorded `create_connection('fritz.box', 49443)` attempts; with the fixtures closing the driver it passes. pytest (74 passed), ruff format/check, mypy, `napalm-standard check` and `ratchet` are green, coverage 81.4 % (floor 81). Closes #11
christianmanivong added 1 commit 2026-11-02 07:38:48 +00:00
fix(tests): close fixture drivers so no test opens a socket
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m14s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / lowest (pull_request) Successful in 28s
driver / build (pull_request) Successful in 38s
driver / security (pull_request) Successful in 1m22s
CI / driver (pull_request) Successful in 2m57s
driver / publish (pull_request) Skipped
244e7f4992
The driver fixtures and test_open_sets_fc_on_success left the driver
open. When it was collected, NAPALM's NetworkDriver.__del__ called
is_alive(), which resolved fritz.box and connected to port 49443 once
per test; the error was swallowed, so it only showed as slow or flaky
runs.

The fixtures now close the driver after the test. A session-wide guard
in conftest refuses every connection and fails the run if any test,
including a __del__, tried one.

Closes #11
christianmanivong merged commit 8b419c54e6 into main 2026-11-02 08:23:34 +00:00
christianmanivong deleted branch fix/bugs-2026-11-02 2026-11-02 08:23:34 +00:00
Sign in to join this conversation.