Commit 86845bf38dbba5fa7499db10ac5ee20f72d3f240

Authored by Simon Glass
Committed by Tom Rini
1 parent 3b8d9d977b

test/py: Provide output from exceptions with RunAndLog()

Tests may want to look at the output from running a command, even if it
fails (e.g. with a non-zero return code). Provide a means to obtain this.

Another approach would be to return a class object containing both the
output and the exception, but I'm not sure if that would result in a lot
of refactoring.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Teddy Reed <teddy.reed@gmail.com>

Showing 1 changed file with 7 additions and 0 deletions Side-by-side Diff

test/py/multiplexed_log.py
... ... @@ -101,6 +101,7 @@
101 101 self.logfile = logfile
102 102 self.name = name
103 103 self.chained_file = chained_file
  104 + self.output = None
104 105  
105 106 def close(self):
106 107 """Clean up any resources managed by this object."""
... ... @@ -109,6 +110,9 @@
109 110 def run(self, cmd, cwd=None, ignore_errors=False):
110 111 """Run a command as a sub-process, and log the results.
111 112  
  113 + The output is available at self.output which can be useful if there is
  114 + an exception.
  115 +
112 116 Args:
113 117 cmd: The command to execute.
114 118 cwd: The directory to run the command in. Can be None to use the
... ... @@ -159,6 +163,9 @@
159 163 self.logfile.write(self, output)
160 164 if self.chained_file:
161 165 self.chained_file.write(output)
  166 +
  167 + # Store the output so it can be accessed if we raise an exception.
  168 + self.output = output
162 169 if exception:
163 170 raise exception
164 171 return output