tests: the driver fixtures open a real socket to fritz.box:49443 when they are garbage-collected #11

Closed
opened 2026-11-01 21:44:47 +00:00 by christianmanivong · 0 comments
Owner

What happens

The driver and pppoe_driver fixtures (tests/unit/test_driver.py 246-288) create FritzBoxDriver(hostname="fritz.box", …), set drv.fc to a MagicMock and yield drv without closing it. When the driver is collected, NAPALM's NetworkDriver.__del__ calls is_alive(), and with fc still set that does a real

with socket.create_connection((self.hostname, self.port), timeout=5):

(napalm_fritzbox/fritzbox.py:159), i.e. a DNS lookup of fritz.box and a TCP connect to port 49443, once per test that used a fixture. In a network with a real FRITZ!Box the connect succeeds; elsewhere each one can wait up to the timeout. Exceptions in __del__ are swallowed, so it only shows up as slow or flaky test runs.

Expected

The fixtures call drv.close() after yield (which sets fc = None, so is_alive returns without touching the network), or patch socket.create_connection for the module. No unit test touches the network.

Priority: P4 — non-hermetic unit tests.

Found during the bug sweep of 2026-11-01.

## What happens The `driver` and `pppoe_driver` fixtures (`tests/unit/test_driver.py` 246-288) create `FritzBoxDriver(hostname="fritz.box", …)`, set `drv.fc` to a `MagicMock` and `yield drv` without closing it. When the driver is collected, NAPALM's `NetworkDriver.__del__` calls `is_alive()`, and with `fc` still set that does a real ```python with socket.create_connection((self.hostname, self.port), timeout=5): ``` (`napalm_fritzbox/fritzbox.py:159`), i.e. a DNS lookup of `fritz.box` and a TCP connect to port 49443, once per test that used a fixture. In a network with a real FRITZ!Box the connect succeeds; elsewhere each one can wait up to the timeout. Exceptions in `__del__` are swallowed, so it only shows up as slow or flaky test runs. ## Expected The fixtures call `drv.close()` after `yield` (which sets `fc = None`, so `is_alive` returns without touching the network), or patch `socket.create_connection` for the module. No unit test touches the network. Priority: P4 — non-hermetic unit tests. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P4
bug
labels 2026-11-01 21:44:47 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-fritzbox#11