bpo-4080: unittest durations (#12271)

This commit is contained in:
Giampaolo Rodola 2023-04-03 00:12:51 +02:00 committed by GitHub
parent a0305c5fdf
commit 6883007a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 227 additions and 34 deletions

View file

@ -9,6 +9,7 @@ import warnings
import collections
import contextlib
import traceback
import time
import types
from . import result
@ -572,6 +573,15 @@ class TestCase(object):
else:
addUnexpectedSuccess(self)
def _addDuration(self, result, elapsed):
try:
addDuration = result.addDuration
except AttributeError:
warnings.warn("TestResult has no addDuration method",
RuntimeWarning)
else:
addDuration(self, elapsed)
def _callSetUp(self):
self.setUp()
@ -612,6 +622,7 @@ class TestCase(object):
getattr(testMethod, "__unittest_expecting_failure__", False)
)
outcome = _Outcome(result)
start_time = time.perf_counter()
try:
self._outcome = outcome
@ -625,6 +636,7 @@ class TestCase(object):
with outcome.testPartExecutor(self):
self._callTearDown()
self.doCleanups()
self._addDuration(result, (time.perf_counter() - start_time))
if outcome.success:
if expecting_failure: