Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.

Commit 29bcd04

Browse files
committed
tests: boardfarm: error out and print the result when pexpect run fails
When a command failed to run, raise an exception early, and add the stdout and stderr output of the command in the message. These changes were taken and adapted from: #1483 Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
1 parent 05c56e5 commit 29bcd04

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

tests/boardfarm_plugins/boardfarm_prplmesh/devices/prplmesh_base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@
88
from boardfarm.devices import linux
99

1010

11+
class CommandError(Exception):
12+
"""Raised on failed execution"""
13+
pass
14+
15+
1116
class PrplMeshBase(linux.LinuxDevice):
1217
"""PrplMesh abstract device."""
1318

1419
def _run_shell_cmd(self, cmd: str = "", args: list = None, timeout: int = 30):
1520
"""Wrapper that executes command with specified args on host machine and logs output."""
1621

17-
res = pexpect.run(cmd, args=args, timeout=timeout, encoding="utf-8")
22+
res, exitstatus = pexpect.run(cmd, args=args, timeout=timeout, encoding="utf-8",
23+
withexitstatus=1)
1824
entry = " ".join((cmd, " ".join(args)))
25+
if exitstatus != 0:
26+
raise CommandError("Error executing {}:\n{}".format(entry, res))
27+
1928
self.log_calls += entry
2029
self.log += "$ " + entry + "\r\n" + res
2130

0 commit comments

Comments
 (0)