tests: test_open_raises_connection_exception_on_error does a real network request #41

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

What happens

TestOpenClose.test_open_raises_connection_exception_on_error (tests/unit/test_driver.py:128-136) builds a driver for hostname="unreachable.invalid" and calls drv.open() without patching anything. open() creates a real requests.Session and GETs /api/core/system/status, so the unit test resolves the name through the machine's resolver and depends on it failing quickly. On a host with a slow or unreachable resolver the test waits for the resolver timeout; with a search domain or a resolver that answers every name, it tries to connect.

napalm-fritzbox's test of the same name patches the connection instead.

Expected

The test patches requests.Session.get (or _get) to raise requests.ConnectionError and asserts ConnectionException and session is None. No unit test touches the network.

Priority: P4 — a non-hermetic unit test.

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

## What happens `TestOpenClose.test_open_raises_connection_exception_on_error` (`tests/unit/test_driver.py:128-136`) builds a driver for `hostname="unreachable.invalid"` and calls `drv.open()` without patching anything. `open()` creates a real `requests.Session` and GETs `/api/core/system/status`, so the unit test resolves the name through the machine's resolver and depends on it failing quickly. On a host with a slow or unreachable resolver the test waits for the resolver timeout; with a search domain or a resolver that answers every name, it tries to connect. napalm-fritzbox's test of the same name patches the connection instead. ## Expected The test patches `requests.Session.get` (or `_get`) to raise `requests.ConnectionError` and asserts `ConnectionException` and `session is None`. No unit test touches the network. Priority: P4 — a non-hermetic unit test. Found during the bug sweep of 2026-11-01.
christianmanivong added the
prio
P4
bug
labels 2026-11-01 21:44:46 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: NAPALM/napalm-opnsense#41