File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments