diff --git a/NEWS b/NEWS index 3e0ff16..b4c9eaa 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ Improvements This was a side effect of the fix to bug #941958, where we fixed a cosmetic error. (Robert Collins, #1430534) +* During reporting in ``TextTestResult`` now always uses ``ceil`` rather than + depending on the undefined rounding behaviour in string formatting. + (Robert Collins) + 1.7.0 ~~~~~ diff --git a/testtools/testresult/real.py b/testtools/testresult/real.py index 3b9ef4e..44e3468 100644 --- a/testtools/testresult/real.py +++ b/testtools/testresult/real.py @@ -23,6 +23,7 @@ __all__ = [ ] import datetime +import math from operator import methodcaller import sys import unittest @@ -888,9 +889,14 @@ class TextTestResult(TestResult): self.sep1 = '=' * 70 + '\n' self.sep2 = '-' * 70 + '\n' - def _delta_to_float(self, a_timedelta): - return (a_timedelta.days * 86400.0 + a_timedelta.seconds + - a_timedelta.microseconds / 1000000.0) + def _delta_to_float(self, a_timedelta, precision): + # This calls ceiling to ensure that the most pessimistic view of time + # taken is shown (rather than leaving it to the Python %f operator + # to decide whether to round/floor/ceiling. This was added when we + # had pyp3 test failures that suggest a floor was happening. + shift = 10 ** precision + return math.ceil((a_timedelta.days * 86400.0 + a_timedelta.seconds + + a_timedelta.microseconds / 1000000.0) * shift) / shift def _show_list(self, label, error_list): for test, output in error_list: @@ -918,7 +924,7 @@ class TextTestResult(TestResult): self.sep1, test.id(), self.sep2)) self.stream.write("\nRan %d test%s in %.3fs\n" % (self.testsRun, plural, - self._delta_to_float(stop - self.__start))) + self._delta_to_float(stop - self.__start, 3))) if self.wasSuccessful(): self.stream.write("OK\n") else: