diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -981,16 +981,16 @@ insane) def test_today(self): - import time + from time import time # We claim that today() is like fromtimestamp(time.time()), so # prove it. for dummy in range(3): today = self.theclass.today() - ts = time.time() + ts = time() todayagain = self.theclass.fromtimestamp(ts) if today == todayagain: - break + return # test passed # There are several legit reasons that could fail: # 1. It recently became midnight, between the today() and the # time() calls. @@ -1000,13 +1000,13 @@ # happened to call today() right before a resolution quantum # boundary. # 4. The system clock got fiddled between calls. - # In any case, wait a little while and try again. - time.sleep(0.1) - - # It worked or it didn't. If it didn't, assume it's reason #2, and - # let the test pass if they're within half a second of each other. - self.assertTrue(today == todayagain or - abs(todayagain - today) < timedelta(seconds=0.5)) + # In any case, try again. + + # If we get here it means that we couldn't get them to be equal even + # after a few attempts, so assume it's reason #2, and let the test + # pass if they're within half a second of each other. + self.assertLess(abs(todayagain - today), timedelta(seconds=0.5), + '\ntodayagain: %r\ntoday : %r' % (todayagain, today)) def test_weekday(self): for i in range(7):