diff mbox series

[02/14] lava_runner: use TextTestRunner

Message ID 20230313094431.507952-3-tzungbi@kernel.org (mailing list archive)
State Handled Elsewhere
Headers show
Series cros-ec-tests: fix some exceptions and clean-ups | expand

Commit Message

Tzung-Bi Shih March 13, 2023, 9:44 a.m. UTC
To simplify, eliminate LavaTestRunner but use TextTestRunner directly.
Also change the constructor of LavaTestResult per [1].

As a side-effect result, it starts to show the following summary:

> Ran 18 tests in 0.010s
>
> FAILED (failures=1, errors=3, skipped=10)

[1]: https://docs.python.org/3/library/unittest.html#unittest.TextTestRunner._makeResult

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 cros/runners/lava_runner.py | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py
index 2e8b1c42bdeb..7524f65dcd39 100755
--- a/cros/runners/lava_runner.py
+++ b/cros/runners/lava_runner.py
@@ -14,57 +14,42 @@  from cros.tests.cros_ec_extcon import *
 
 
 class LavaTestResult(unittest.TestResult):
-    def __init__(self, runner):
+    def __init__(self, stream, descriptions, verbosity):
         unittest.TestResult.__init__(self)
-        self.runner = runner
+        self.stream = stream
 
     def addSuccess(self, test):
         unittest.TestResult.addSuccess(self, test)
-        self.runner.writeUpdate(
+        self.stream.write(
             "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=pass>\n"
             % test.id().rsplit(".")[-1]
         )
 
     def addError(self, test, err):
         unittest.TestResult.addError(self, test, err)
-        self.runner.writeUpdate(
+        self.stream.write(
             "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=unknown>\n"
             % test.id().rsplit(".")[-1]
         )
 
     def addFailure(self, test, err):
         unittest.TestResult.addFailure(self, test, err)
-        self.runner.writeUpdate(
+        self.stream.write(
             "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=fail>\n"
             % test.id().rsplit(".")[-1]
         )
 
     def addSkip(self, test, reason):
         unittest.TestResult.addSkip(self, test, reason)
-        self.runner.writeUpdate(
+        self.stream.write(
             "<LAVA_SIGNAL_TESTCASE TEST_CASE_ID=%s RESULT=skip>\n"
             % test.id().rsplit(".")[-1]
         )
 
 
-class LavaTestRunner:
-    def __init__(self, stream=sys.stderr, verbosity=0):
-        self.stream = stream
-        self.verbosity = verbosity
-
-    def writeUpdate(self, message):
-        self.stream.write(message)
-
-    def run(self, test):
-        result = LavaTestResult(self)
-        test(result)
-        result.testsRun
-        return result
-
-
 if __name__ == "__main__":
     unittest.main(
-        testRunner=LavaTestRunner(),
+        testRunner=unittest.TextTestRunner(resultclass=LavaTestResult),
         # these make sure that some options that are not applicable
         # remain hidden from the help menu.
         failfast=False,