The unit tests open no socket any more, and a guard keeps it that way.
tests/conftest.py: a session-wide autouse fixture, as in NAPALM/napalm-fritzbox#11. It replaces socket.create_connection and socket.socket.connect with functions that record the attempt and refuse it. After a final gc.collect() it fails the run if anything tried to connect. A connection attempted from __del__ is swallowed there, which is why attempts are recorded rather than only raised.
tests/test_zyxel.py: every driver the tests build goes through _offline(), which gives the instance an is_alive() that opens nothing. The two is_alive tests call ZyxelVMGDriver.is_alive(self.driver) with socket.create_connection patched, as before. tests/test_failed_reads.py already stubbed it (#16).
Why
NAPALM's NetworkDriver.__del__ calls is_alive(), and this driver's is_alive() (zyxel_driver.py:212) connects to the gateway over TCP. Every driver a test built connected to 192.168.1.1:80 when it was collected. Closing the drivers would not help: is_alive() connects whether or not the driver was opened or closed, so the tests stub it.
The driver itself is unchanged. is_alive() reporting the session state instead of reachability would also stop a closed driver from connecting on garbage collection, but that is a behaviour change outside this issue. netOrk never calls is_alive().
Tests
Fixtures only (no device). With only the guard added, the run failed with unit tests tried to open a socket: ["create_connection('192.168.1.1', 80)", …]. With the stubs it passes: 66 passed, repeated three times.
ruff format/check clean, mypy clean, napalm-standard check passes, napalm-standard ratchet within the baseline. No CHANGELOG entry: nothing changes for driver users (same as fritzbox#11).
## What
The unit tests open no socket any more, and a guard keeps it that way.
- `tests/conftest.py`: a session-wide autouse fixture, as in NAPALM/napalm-fritzbox#11. It replaces `socket.create_connection` and `socket.socket.connect` with functions that record the attempt and refuse it. After a final `gc.collect()` it fails the run if anything tried to connect. A connection attempted from `__del__` is swallowed there, which is why attempts are recorded rather than only raised.
- `tests/test_zyxel.py`: every driver the tests build goes through `_offline()`, which gives the instance an `is_alive()` that opens nothing. The two `is_alive` tests call `ZyxelVMGDriver.is_alive(self.driver)` with `socket.create_connection` patched, as before. `tests/test_failed_reads.py` already stubbed it (#16).
## Why
NAPALM's `NetworkDriver.__del__` calls `is_alive()`, and this driver's `is_alive()` (`zyxel_driver.py:212`) connects to the gateway over TCP. Every driver a test built connected to 192.168.1.1:80 when it was collected. Closing the drivers would not help: `is_alive()` connects whether or not the driver was opened or closed, so the tests stub it.
The driver itself is unchanged. `is_alive()` reporting the session state instead of reachability would also stop a closed driver from connecting on garbage collection, but that is a behaviour change outside this issue. netOrk never calls `is_alive()`.
## Tests
Fixtures only (no device). With only the guard added, the run failed with `unit tests tried to open a socket: ["create_connection('192.168.1.1', 80)", …]`. With the stubs it passes: 66 passed, repeated three times.
ruff format/check clean, mypy clean, `napalm-standard check` passes, `napalm-standard ratchet` within the baseline. No CHANGELOG entry: nothing changes for driver users (same as fritzbox#11).
Closes #17
NAPALM's __del__ calls is_alive(), and this driver's is_alive() opens a
TCP connection to the gateway whether or not the driver was opened or
closed, so every driver a test built connected to 192.168.1.1:80 when
it was collected. The tests now build their drivers with an is_alive()
that opens nothing (the is_alive tests call the class's method), and a
session-wide guard in conftest refuses every connection and fails the
run if anything tried one.
Closes#17
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
The unit tests open no socket any more, and a guard keeps it that way.
tests/conftest.py: a session-wide autouse fixture, as in NAPALM/napalm-fritzbox#11. It replacessocket.create_connectionandsocket.socket.connectwith functions that record the attempt and refuse it. After a finalgc.collect()it fails the run if anything tried to connect. A connection attempted from__del__is swallowed there, which is why attempts are recorded rather than only raised.tests/test_zyxel.py: every driver the tests build goes through_offline(), which gives the instance anis_alive()that opens nothing. The twois_alivetests callZyxelVMGDriver.is_alive(self.driver)withsocket.create_connectionpatched, as before.tests/test_failed_reads.pyalready stubbed it (#16).Why
NAPALM's
NetworkDriver.__del__callsis_alive(), and this driver'sis_alive()(zyxel_driver.py:212) connects to the gateway over TCP. Every driver a test built connected to 192.168.1.1:80 when it was collected. Closing the drivers would not help:is_alive()connects whether or not the driver was opened or closed, so the tests stub it.The driver itself is unchanged.
is_alive()reporting the session state instead of reachability would also stop a closed driver from connecting on garbage collection, but that is a behaviour change outside this issue. netOrk never callsis_alive().Tests
Fixtures only (no device). With only the guard added, the run failed with
unit tests tried to open a socket: ["create_connection('192.168.1.1', 80)", …]. With the stubs it passes: 66 passed, repeated three times.ruff format/check clean, mypy clean,
napalm-standard checkpasses,napalm-standard ratchetwithin the baseline. No CHANGELOG entry: nothing changes for driver users (same as fritzbox#11).Closes #17