From ee26a1ca85fc5fac6df6c39f362fad83de73c0cc Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Fri, 5 May 2017 14:38:27 +0200 Subject: Print the real testcase duration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestCase offers a new public method to calculate and print the duration. It also adds the related unit tests and adapts run_tests.py. Change-Id: Ib6a7e637dafacb9027146199aeb033c2dcb986c6 Signed-off-by: Cédric Ollivier --- functest/core/testcase.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'functest/core/testcase.py') diff --git a/functest/core/testcase.py b/functest/core/testcase.py index 217f07e51..fd8928494 100644 --- a/functest/core/testcase.py +++ b/functest/core/testcase.py @@ -43,6 +43,24 @@ class TestCase(object): self.start_time = "" self.stop_time = "" + def get_duration(self): + """Return the duration of the test case. + + Returns: + duration if start_time and stop_time are set + "XX:XX" otherwise. + """ + try: + assert self.start_time + assert self.stop_time + if self.stop_time < self.start_time: + return "XX:XX" + return "{0[0]:02.0f}:{0[1]:02.0f}".format(divmod( + self.stop_time - self.start_time, 60)) + except Exception: + self.__logger.error("Please run test before getting the duration") + return "XX:XX" + def check_result(self): """Interpret the result of the test case. -- cgit 1.2.3-korg