From 87c1442469e76e338ee7eb0606e7e8caa525e056 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 7 Jan 2015 10:52:24 -0500 Subject: [PATCH] Fix subunit-trace on python < 2.7 This commit fixes running subunit-trace on older versions of python, by inlining the total_seconds method from newer versions of python. While tempest-lib is nominally only for python > 2.7 (which is all we test) subunit-trace is slightly different. Since it is expected to be used in the unit test workflows of projects, some of which still run on older python. Change-Id: I33c337bfb376a27bf02cc2d16a69dafba2cea41f --- tempest_lib/cmd/subunit_trace.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tempest_lib/cmd/subunit_trace.py b/tempest_lib/cmd/subunit_trace.py index 64e1537..ea59cc6 100755 --- a/tempest_lib/cmd/subunit_trace.py +++ b/tempest_lib/cmd/subunit_trace.py @@ -33,6 +33,13 @@ FAILS = [] RESULTS = {} +def total_seconds(timedelta): + # NOTE(mtreinish): This method is built-in to the timedelta class in + # python >= 2.7 it is here to enable it's use on older versions + return ((timedelta.days * DAY_SECONDS + timedelta.seconds) * 10 ** 6 + + timedelta.microseconds) / 10 ** 6 + + def cleanup_test_name(name, strip_tags=True, strip_scenarios=False): """Clean up the test name for display. @@ -192,7 +199,7 @@ def worker_stats(worker): def print_summary(stream, elapsed_time): stream.write("\n======\nTotals\n======\n") stream.write("Ran: %s tests in %.4f sec.\n" % ( - count_tests('status', '.*'), elapsed_time.total_seconds())) + count_tests('status', '.*'), total_seconds(elapsed_time))) stream.write(" - Passed: %s\n" % count_tests('status', 'success')) stream.write(" - Skipped: %s\n" % count_tests('status', 'skip')) stream.write(" - Failed: %s\n" % count_tests('status', 'fail'))