From fe71a7864e7fa647186e658514bd1ce2ffe599b1 Mon Sep 17 00:00:00 2001 From: horw Date: Tue, 8 Oct 2024 21:43:17 +0800 Subject: [PATCH] fix: close serial port when exception --- pytest-embedded-serial/pytest_embedded_serial/serial.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pytest-embedded-serial/pytest_embedded_serial/serial.py b/pytest-embedded-serial/pytest_embedded_serial/serial.py index 99c5a818..f694673c 100644 --- a/pytest-embedded-serial/pytest_embedded_serial/serial.py +++ b/pytest-embedded-serial/pytest_embedded_serial/serial.py @@ -91,8 +91,11 @@ def __init__( self.ports_to_occupy.append(self.port) self._post_init() - self._start() - + try: + self._start() + except Exception as e: + self.close() + raise e self._finalize_init() if not stop_after_init: self.start_redirect_thread()