hftest.py: Load 'serial' module lazily
Build servers may not have the pyserial package installed, but they
don't use the SerialDriver to run tests. Load it lazily to avoid it
being a hard requirement.
Change-Id: Iefe30e76a57569c0fd6f64cdae7da04fbfe95833
diff --git a/test/hftest/hftest.py b/test/hftest/hftest.py
index 5e1d200..e3ee493 100755
--- a/test/hftest/hftest.py
+++ b/test/hftest/hftest.py
@@ -25,10 +25,10 @@
import argparse
import collections
import datetime
+import importlib
import json
import os
import re
-import serial
import subprocess
import sys
@@ -366,12 +366,13 @@
Driver.__init__(self, args)
self.tty_file = tty_file
self.baudrate = baudrate
+ self.pyserial = importlib.import_module("serial")
if init_wait:
input("Press ENTER and then reset the device...")
def connect(self):
- return serial.Serial(self.tty_file, self.baudrate, timeout=10)
+ return self.pyserial.Serial(self.tty_file, self.baudrate, timeout=10)
def run(self, run_name, test_args, is_long_running):
"""Communicate `test_args` to the device over the serial port."""