Skip to content

Commit

Permalink
Don't try to get elapsed time of a skipped test
Browse files Browse the repository at this point in the history
In Python 3.12.1, tests that are entirely skipped
never called startTest(), so we can't calculate
an elapsed time. Just report zero in this case.
  • Loading branch information
benmwebb committed Dec 20, 2023
1 parent e035dd8 commit 57d482d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions modules/test/pyext/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,20 @@ def startTest(self, test):
test.start_time = datetime.datetime.now()

def _test_finished(self, test, state, detail=None):
delta = datetime.datetime.now() - test.start_time
try:
pv = delta.total_seconds()
except AttributeError:
pv = (float(delta.microseconds)
+ (delta.seconds + delta.days * 24 * 3600) * 10**6) / 10**6
if pv > 1:
self.stream.write("in %.3fs ... " % pv)
if hasattr(test, 'start_time'):
delta = datetime.datetime.now() - test.start_time
try:
pv = delta.total_seconds()
except AttributeError:
pv = (float(delta.microseconds)
+ (delta.seconds
+ delta.days * 24 * 3600) * 10**6) / 10**6
if pv > 1:
self.stream.write("in %.3fs ... " % pv)
else:
# If entire test was skipped, startTest() may not have been
# called, in which case start_time won't be set
pv = 0
if detail is not None and not isinstance(detail, str):
detail = self._exc_info_to_string(detail, test)
test_doc = self.getDescription(test)
Expand Down

0 comments on commit 57d482d

Please sign in to comment.