From 6909d3d21fc33074e0b01fc4c73aa0477d09a1f0 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sun, 31 May 2026 15:10:37 -0700 Subject: [PATCH] make test more deterministic for reconnect count testing --- meshtastic/tests/test_tcp_interface.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/meshtastic/tests/test_tcp_interface.py b/meshtastic/tests/test_tcp_interface.py index 5857a7c..4f0fec9 100644 --- a/meshtastic/tests/test_tcp_interface.py +++ b/meshtastic/tests/test_tcp_interface.py @@ -110,11 +110,10 @@ def test_TCPInterface_writeBytes_reconnects(): @pytest.mark.unit def test_TCPInterface_readBytes_reconnects(): """Test that _readBytes calls _reconnect on empty bytes""" - with patch("socket.socket"): - iface = TCPInterface(hostname="localhost", noProto=True) - # Mock the socket instance on the interface - iface.socket.recv.return_value = b'' + iface = TCPInterface(hostname="localhost", noProto=True, connectNow=False) + iface.socket = MagicMock() + iface.socket.recv.return_value = b"" - with patch.object(iface, '_reconnect') as mock_reconnect: - iface._readBytes(10) - mock_reconnect.assert_called_once() + with patch.object(iface, "_reconnect") as mock_reconnect: + iface._readBytes(10) + mock_reconnect.assert_called_once()