Skip to content

Commit 635e115

Browse files
committed
Apply review suggestion
1 parent 035834b commit 635e115

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

tests/test_connection.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,19 @@ def controlled_read(_size: int) -> bytes:
104104

105105
with mock.patch("serial.serial_for_url", return_value=mock_ser):
106106
connection = YncaConnection("dummy_port")
107-
connection.connect(disconnect_callback=disconnect_callback)
108107

109-
# Trigger the simulated disconnect; controlled_read raises SerialException
110-
# which the ReaderThread detects and routes to connection_lost().
111-
read_should_fail.set()
108+
try:
109+
connection.connect(disconnect_callback=disconnect_callback)
112110

113-
assert disconnect_event.wait(
114-
timeout=2.0
115-
), "Disconnect callback not called within timeout"
111+
# Trigger the simulated disconnect; controlled_read raises SerialException
112+
# which the ReaderThread detects and routes to connection_lost().
113+
read_should_fail.set()
114+
115+
assert disconnect_event.wait(
116+
timeout=2.0
117+
), "Disconnect callback not called within timeout"
118+
finally:
119+
connection.close()
116120

117121
assert disconnect_callback.call_count == 1
118122

0 commit comments

Comments
 (0)