Message ID | 1467560446-10628-7-git-send-email-sjg@chromium.org |
---|---|
State | Accepted |
Commit | 86845bf38dbba5fa7499db10ac5ee20f72d3f240 |
Delegated to: | Tom Rini |
Headers | show |
Hi Simon, On Sun, Jul 3, 2016 at 8:40 AM, Simon Glass <sjg@chromium.org> wrote: > 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. In my experience with Pytest/Gtest _not_ using a class to represent output/exception is the way to go! Then a test author can write test cases with a flow like: ASSERT_NOEXCEPT(output = doAction()) EXPECT_EQUAL(2, output) The test harness can provide much more succinct errors when these cases fail. :) > > Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Teddy Reed <teddy.reed@gmail.com> > --- > > test/py/multiplexed_log.py | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py > index 02c44df..35a32fb 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 > -- > 2.8.0.rc3.226.g39d4020 > > _______________________________________________ > U-Boot mailing list > U-Boot@lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot
On Sun, Jul 03, 2016 at 09:40:38AM -0600, Simon Glass wrote: > 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> Applied to u-boot/master, thanks!
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 02c44df..35a32fb 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
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> --- test/py/multiplexed_log.py | 7 +++++++ 1 file changed, 7 insertions(+)