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 <michal.smola@nxp.com>
This commit is contained in:
parent
62f1105550
commit
5c78b3d842
1 changed files with 9 additions and 2 deletions
|
@ -6,7 +6,8 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
import os
|
||||
import pty
|
||||
if os.name != 'nt':
|
||||
import pty
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
|
@ -150,7 +151,13 @@ class HardwareAdapter(DeviceAdapter):
|
|||
"""Open a pty pair, run process and return tty name"""
|
||||
if not self.device_config.serial_pty:
|
||||
return None
|
||||
master, slave = pty.openpty()
|
||||
|
||||
try:
|
||||
master, slave = pty.openpty()
|
||||
except NameError as exc:
|
||||
logger.exception('PTY module is not available.')
|
||||
raise exc
|
||||
|
||||
try:
|
||||
self._serial_pty_proc = subprocess.Popen(
|
||||
re.split(',| ', self.device_config.serial_pty),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue