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
This commit is contained in:
Matthew Treinish
2015-01-07 10:52:24 -05:00
parent b73b9eb2a0
commit 87c1442469

View File

@@ -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'))