Skip to content

Commit

Permalink
fix: close serial port when exception
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Oct 8, 2024
1 parent 0cbd304 commit 702d821
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pytest-embedded-serial/pytest_embedded_serial/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ def __init__(
self.proc = pyserial.serial_for_url(self.port, **port_config)

self.ports_to_occupy.append(self.port)
self._post_init()
self._start()
try:
self._post_init()
self._start()

self._finalize_init()
if not stop_after_init:
self.start_redirect_thread()
else:
self._finalize_init()
if not stop_after_init:
self.start_redirect_thread()
else:
self.close()
except Exception as e:
self.close()
raise e

def start_redirect_thread(self) -> None:
if self._redirect_thread and self._redirect_thread.is_alive():
Expand Down

0 comments on commit 702d821

Please sign in to comment.