@@ -13,38 +13,34 @@ from cros.tests.cros_ec_power import *
from cros.tests.cros_ec_extcon import *
-class LavaTestResult(unittest.TestResult):
- def __init__(self, stream, descriptions, verbosity):
- unittest.TestResult.__init__(self)
- self.stream = stream
+class LavaTestResult(unittest.TextTestResult):
+ def writeLavaSignal(self, test, result):
+ test_case_id = test.id().rsplit(".")[-1]
- def addSuccess(self, test):
- unittest.TestResult.addSuccess(self, test)
- self.stream.write(
- "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=pass>\n"
- % test.id().rsplit(".")[-1]
+ # LAVA signal must be start-of-line. Print a newline if verbosity >= 1.
+ if self.showAll or self.dots:
+ self.stream.writeln()
+
+ self.stream.writeln(
+ f"<LAVA_SIGNAL_TESTCASE TEST_CASE_ID={test_case_id} RESULT={result}>"
)
+ self.stream.flush()
+
+ def addSuccess(self, test):
+ super().addSuccess(test)
+ self.writeLavaSignal(test, "pass")
def addError(self, test, err):
- unittest.TestResult.addError(self, test, err)
- self.stream.write(
- "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=unknown>\n"
- % test.id().rsplit(".")[-1]
- )
+ super().addError(test, err)
+ self.writeLavaSignal(test, "unknown")
def addFailure(self, test, err):
- unittest.TestResult.addFailure(self, test, err)
- self.stream.write(
- "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=fail>\n"
- % test.id().rsplit(".")[-1]
- )
+ super().addFailure(test, err)
+ self.writeLavaSignal(test, "fail")
def addSkip(self, test, reason):
- unittest.TestResult.addSkip(self, test, reason)
- self.stream.write(
- "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=skip>\n"
- % test.id().rsplit(".")[-1]
- )
+ super().addSkip(test, reason)
+ self.writeLavaSignal(test, "skip")
if __name__ == "__main__":
To simplify, make LavaTestResult is-a TextTestResult. As a side-effect result, it prints errors and fails by the end of test running. See [1]. [1]: https://github.com/python/cpython/blob/main/Lib/unittest/runner.py#L139 Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org> --- cros/runners/lava_runner.py | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-)