make test more deterministic for reconnect count testing

This commit is contained in:
Ian McEwen committed 2026-05-31 15:10:37 -07:00
1 parent dbf4cabee1
commit 6909d3d21f
1 file changed
+6 -7
+6 -7
View File
@@ -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()