patman: test_util: Print test stdout/stderr within test summaries
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>
Sat, 2 Apr 2022 17:06:08 +0000 (20:06 +0300)
committerSimon Glass <sjg@chromium.org>
Tue, 28 Jun 2022 02:09:51 +0000 (03:09 +0100)
commitebcaafcded40da8ae6cb4234c2ba9901c7bee644
tree3e1adb9dd654f0bf2107765f25da91f127408f90
parentdd6b92b0b9532bb4ba0ad8ac3620b1f3b81adf5b
patman: test_util: Print test stdout/stderr within test summaries

While running tests for a python tool, the tests' outputs get printed in
whatever order they happen to run, without any indication as to which
output belongs to which test. Unittest supports capturing these outputs
and printing them as part of the test summaries, but when a failure or
error occurs it switches back to printing as the tests run. Testtools
and subunit tests can do the same as their parts inherit from unittest,
but they don't outright expose this functionality.

On the unittest side, enable output buffering for the custom test result
class. Try to avoid ugly outputs by not printing stdout/stderr before
the test summary for low verbosity levels and for successful tests.

On the subunit side, implement a custom TestProtocolClient that enables
the same underlying functionality and injects the captured streams as
additional test details. This causes them to be merged into their test's
error traceback message, which is later rebuilt into an exception and
passed to our unittest report class.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/concurrencytest/concurrencytest.py
tools/patman/test_util.py