bpo-41718: libregrtest avoids importing datetime (GH-24985)

* libregrtest reimplements datetime.timedelta.__str__()
* support.testresult only imports datetime if USE_XML is true.
This commit is contained in:
Victor Stinner 2021-03-23 01:40:31 +01:00 committed by GitHub
parent 30793e81bd
commit 9feae41c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,3 @@
import datetime
import faulthandler
import locale
import os
@ -150,9 +149,12 @@ class Regrtest:
# add the timestamp prefix: "0:01:05 "
test_time = time.monotonic() - self.start_time
test_time = datetime.timedelta(seconds=int(test_time))
line = f"{test_time} {line}"
mins, secs = divmod(int(test_time), 60)
hours, mins = divmod(mins, 60)
test_time = "%d:%02d:%02d" % (hours, mins, secs)
line = f"{test_time} {line}"
if empty:
line = line[:-1]

View File

@ -9,8 +9,6 @@ import time
import traceback
import unittest
from datetime import datetime
class RegressionTestResult(unittest.TextTestResult):
separator1 = '=' * 70 + '\n'
separator2 = '-' * 70 + '\n'
@ -21,6 +19,7 @@ class RegressionTestResult(unittest.TextTestResult):
self.buffer = True
if self.USE_XML:
from xml.etree import ElementTree as ET
from datetime import datetime
self.__ET = ET
self.__suite = ET.Element('testsuite')
self.__suite.set('start', datetime.utcnow().isoformat(' '))