Skip to content

Commit 5c78b3d

Browse files
michal-smolafabiobaltieri
authored andcommitted
twister: pytest: fix pty import on Windows
Import of pty module causes exception when pytest harness is used for device testing on Windows. Fix it by importing pty module on non-windows hosts only. Add logger message for case pty is used by mistake on Windows. Signed-off-by: Michal Smola <[email protected]>
1 parent 62f1105 commit 5c78b3d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import logging
88
import os
9-
import pty
9+
if os.name != 'nt':
10+
import pty
1011
import re
1112
import subprocess
1213
import time
@@ -150,7 +151,13 @@ def _open_serial_pty(self) -> str | None:
150151
"""Open a pty pair, run process and return tty name"""
151152
if not self.device_config.serial_pty:
152153
return None
153-
master, slave = pty.openpty()
154+
155+
try:
156+
master, slave = pty.openpty()
157+
except NameError as exc:
158+
logger.exception('PTY module is not available.')
159+
raise exc
160+
154161
try:
155162
self._serial_pty_proc = subprocess.Popen(
156163
re.split(',| ', self.device_config.serial_pty),

0 commit comments

Comments
 (0)