diff options
author | Simon Glass <sjg@chromium.org> | 2016-07-03 09:40:38 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-07-14 18:22:34 -0400 |
commit | 86845bf38dbba5fa7499db10ac5ee20f72d3f240 (patch) | |
tree | e66c110c815cdc09a948fa5156a653d5da3d8a58 | |
parent | 3b8d9d977b6dd6d04f0cfe2eb5dce25264fe40f5 (diff) |
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>
-rw-r--r-- | test/py/multiplexed_log.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 02c44df883a..35a32fb5c05 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -101,6 +101,7 @@ class RunAndLog(object): self.logfile = logfile self.name = name self.chained_file = chained_file + self.output = None def close(self): """Clean up any resources managed by this object.""" @@ -109,6 +110,9 @@ class RunAndLog(object): def run(self, cmd, cwd=None, ignore_errors=False): """Run a command as a sub-process, and log the results. + The output is available at self.output which can be useful if there is + an exception. + Args: cmd: The command to execute. cwd: The directory to run the command in. Can be None to use the @@ -159,6 +163,9 @@ class RunAndLog(object): self.logfile.write(self, output) if self.chained_file: self.chained_file.write(output) + + # Store the output so it can be accessed if we raise an exception. + self.output = output if exception: raise exception return output |