pytest-embedded-serial 2.1.2__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-embedded-serial
3
- Version: 2.1.2
3
+ Version: 2.2.0
4
4
  Summary: Make pytest-embedded plugin work with Serial.
5
5
  Author-email: Fu Hanxi <fuhanxi@espressif.com>
6
6
  Requires-Python: >=3.10
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python
20
20
  Classifier: Topic :: Software Development :: Testing
21
21
  License-File: LICENSE
22
- Requires-Dist: pytest-embedded~=2.1.2
22
+ Requires-Dist: pytest-embedded~=2.2.0
23
23
  Requires-Dist: pyserial~=3.0
24
24
  Project-URL: changelog, https://github.com/espressif/pytest-embedded/blob/main/CHANGELOG.md
25
25
  Project-URL: documentation, https://docs.espressif.com/projects/pytest-embedded/en/latest/
@@ -28,7 +28,7 @@ dynamic = ["version", "description"]
28
28
  requires-python = ">=3.10"
29
29
 
30
30
  dependencies = [
31
- "pytest-embedded~=2.1.2",
31
+ "pytest-embedded~=2.2.0",
32
32
  "pyserial~=3.0",
33
33
  ]
34
34
 
@@ -8,4 +8,4 @@ __all__ = [
8
8
  'SerialDut',
9
9
  ]
10
10
 
11
- __version__ = '2.1.2'
11
+ __version__ = '2.2.0'
@@ -193,8 +193,53 @@ class _SerialRedirectThread(threading.Thread):
193
193
 
194
194
  try:
195
195
  s = self._s.read_all()
196
+ except OSError as e:
197
+ logging.error(f'OSError detected: {e}. Serial connection may be lost.')
198
+ if self._s.closed:
199
+ logging.error('Serial port is already closed. Exiting event loop.')
200
+ return
201
+
202
+ port = self._s.port
203
+ port_config = {
204
+ 'baudrate': self._s.baudrate,
205
+ 'bytesize': self._s.bytesize,
206
+ 'parity': self._s.parity,
207
+ 'stopbits': self._s.stopbits,
208
+ 'timeout': self._s.timeout,
209
+ 'xonxoff': self._s.xonxoff,
210
+ 'rtscts': self._s.rtscts,
211
+ }
212
+ for attempt in range(1, 4):
213
+ delay = attempt * 1.5
214
+ logging.warning(
215
+ f'Attempting to reconnect to serial port {port} (try {attempt}/3) after {delay}s...'
216
+ )
217
+ time.sleep(delay)
218
+ try:
219
+ self._s.close()
220
+ self._s = pyserial.serial_for_url(port, **port_config)
221
+ logging.info(f'Successfully reconnected to serial port {port}.')
222
+ break
223
+ except Exception as e:
224
+ logging.warning(f'Reconnection attempt {attempt} failed: {e}')
225
+ else:
226
+ logging.error(
227
+ f'Failed to reconnect to serial port {port} after 3 attempts. Exiting event loop.'
228
+ )
229
+ return
230
+
231
+ continue
232
+
233
+ except Exception as e:
234
+ logging.warning(
235
+ 'unknown error: %s.\nRecommend to close the serial process by `dut.serial.close()`', str(e)
236
+ )
237
+ return
238
+
239
+ try:
196
240
  self._q.put(s)
197
- except OSError:
241
+ except OSError as e:
242
+ logging.warning(f'OSError. Error msg: {e}')
198
243
  return
199
244
  except Exception as e:
200
245
  logging.warning(