From 96a4a139d077ac9071c312e9c363b85718bc5860 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Mon, 2 Nov 2026 08:37:58 +0100 Subject: [PATCH] fix(tests): keep the open() failure test off the network test_open_raises_connection_exception_on_error called open() on "unreachable.invalid" unpatched, so the unit test resolved the name through the host's resolver and depended on it failing fast. Patch requests.Session.get to refuse the connection and check that open() raises ConnectionException and leaves no session behind. Closes #41 --- CHANGELOG.md | 3 +++ tests/unit/test_driver.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e0655a..1f1d8d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,9 @@ All notable changes to this driver. The format follows the reservation anyway: a retry then failed with "Kea rejected DHCP reservation" instead of the real error, or left two reservations for one address, which Kea refuses to load (#40). +- The unit tests no longer reach the network: the test of a failed `open()` looked + up a real host name and waited for the resolver, so it hung or behaved differently + on a build host with a slow resolver or one that answers every name (#41). ## [0.5.0] - 2026-10-23 diff --git a/tests/unit/test_driver.py b/tests/unit/test_driver.py index 9ce694b..c539b2d 100644 --- a/tests/unit/test_driver.py +++ b/tests/unit/test_driver.py @@ -132,8 +132,14 @@ class TestOpenClose: password="s", optional_args={"verify": False}, ) - with pytest.raises(ConnectionException): - drv.open() + refused = requests.exceptions.ConnectionError("Connection refused") + with patch.object(requests.Session, "get", side_effect=refused) as get: + with pytest.raises(ConnectionException, match="Connection refused"): + drv.open() + + get.assert_called_once() + assert get.call_args.args[0] == "https://unreachable.invalid/api/core/system/status" + assert drv.session is None def test_close_clears_session(self, driver): driver.close()