Message ID | 3e3ef4e45b435317b2a6e60da1007ef6b4cf774d.1671873478.git.yann.morin.1998@free.fr |
---|---|
State | Accepted |
Headers | show |
Series | support/testing: misc improvements (branch yem/runtime-test-ppd) | expand |
On Sat, 24 Dec 2022 10:18:11 +0100 "Yann E. MORIN" <yann.morin.1998@free.fr> wrote: > Currently, when asserting that a command succeeded, we just capture the > return code of the command. If that is not zero, the assertion fails, > but the error message is not very splicit: > AssertionError: 1 != 0 > > Replace the error message with an explicit message that dumps the failed > command, the error code, and the resulting output. > > Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr> > Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> > --- > support/testing/infra/basetest.py | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) Applied to master, thanks. Thomas
diff --git a/support/testing/infra/basetest.py b/support/testing/infra/basetest.py index 96c6848dfc..45bcd4c2e2 100644 --- a/support/testing/infra/basetest.py +++ b/support/testing/infra/basetest.py @@ -88,7 +88,12 @@ class BRTest(BRConfigTest): super(BRTest, self).tearDown() # Run the given 'cmd' with a 'timeout' on the target and - # assert that the command succeeded + # assert that the command succeeded; on error, print the + # faulty command and its output def assertRunOk(self, cmd, timeout=-1): - _, exit_code = self.emulator.run(cmd, timeout) - self.assertEqual(exit_code, 0) + out, exit_code = self.emulator.run(cmd, timeout) + self.assertEqual( + exit_code, + 0, + "\nFailed to run: {}\noutput was:\n{}".format(cmd, ' '+'\n '.join(out)) + )
Currently, when asserting that a command succeeded, we just capture the return code of the command. If that is not zero, the assertion fails, but the error message is not very splicit: AssertionError: 1 != 0 Replace the error message with an explicit message that dumps the failed command, the error code, and the resulting output. Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> --- support/testing/infra/basetest.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)