Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69649f2

Browse files
committed
regrtest: display test duration in sequential mode
Only display duration if a test takes more than 30 seconds.
1 parent e985726 commit 69649f2

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

Lib/test/libregrtest/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from test.libregrtest.runtest import (
1414
findtests, runtest,
1515
STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED,
16-
INTERRUPTED, CHILD_ERROR)
16+
INTERRUPTED, CHILD_ERROR,
17+
PROGRESS_MIN_TIME)
1718
from test.libregrtest.setup import setup_tests
1819
from test import support
1920
try:
@@ -293,8 +294,15 @@ def run_tests_sequential(self):
293294

294295
save_modules = sys.modules.keys()
295296

297+
previous_test = None
296298
for test_index, test in enumerate(self.tests, 1):
297-
self.display_progress(test_index, test)
299+
start_time = time.monotonic()
300+
301+
text = test
302+
if previous_test:
303+
text = '%s -- %s' % (text, previous_test)
304+
self.display_progress(test_index, text)
305+
298306
if self.tracer:
299307
# If we're tracing code coverage, then we don't exit with status
300308
# if on a false return value from main.
@@ -311,6 +319,12 @@ def run_tests_sequential(self):
311319
else:
312320
self.accumulate_result(test, result)
313321

322+
test_time = time.monotonic() - start_time
323+
if test_time >= PROGRESS_MIN_TIME:
324+
previous_test = '%s took %.0f sec' % (test, test_time)
325+
else:
326+
previous_test = None
327+
314328
if self.ns.findleaks:
315329
gc.collect()
316330
if gc.garbage:
@@ -326,6 +340,9 @@ def run_tests_sequential(self):
326340
if module not in save_modules and module.startswith("test."):
327341
support.unload(module)
328342

343+
if previous_test:
344+
print(previous_test)
345+
329346
def _test_forever(self, tests):
330347
while True:
331348
for test in tests:

Lib/test/libregrtest/runtest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
INTERRUPTED = -4
2121
CHILD_ERROR = -5 # error in a child process
2222

23+
# Minimum duration of a test to display its duration or to mention that
24+
# the test is running in background
25+
PROGRESS_MIN_TIME = 30.0 # seconds
26+
27+
2328

2429
# small set of tests to determine if we have a basically functioning interpreter
2530
# (i.e. if any of these fail, then anything else is likely to follow)

Lib/test/libregrtest/runtest_mp.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
print("Multiprocess option requires thread support")
1414
sys.exit(2)
1515

16-
from test.libregrtest.runtest import runtest, INTERRUPTED, CHILD_ERROR
16+
from test.libregrtest.runtest import (
17+
runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME)
1718
from test.libregrtest.setup import setup_tests
1819

1920

20-
# Minimum duration of a test to display its duration or to mention that
21-
# the test is running in background
22-
PROGRESS_MIN_TIME = 30.0 # seconds
23-
2421
# Display the running tests if nothing happened last N seconds
2522
PROGRESS_UPDATE = 30.0 # seconds
2623

Lib/test/test_regrtest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_option_and_arg(self):
304304
class BaseTestCase(unittest.TestCase):
305305
TEST_UNIQUE_ID = 1
306306
TESTNAME_PREFIX = 'test_regrtest_'
307-
TESTNAME_REGEX = r'test_[a-z0-9_]+'
307+
TESTNAME_REGEX = r'test_[a-zA-Z0-9_]+'
308308

309309
def setUp(self):
310310
self.testdir = os.path.realpath(os.path.dirname(__file__))
@@ -351,7 +351,8 @@ def check_line(self, output, regex):
351351
self.assertRegex(output, regex)
352352

353353
def parse_executed_tests(self, output):
354-
regex = r'^[0-9]+:[0-9]+:[0-9]+ \[ *[0-9]+(?:/ *[0-9]+)?\] (%s)$' % self.TESTNAME_REGEX
354+
regex = (r'^[0-9]+:[0-9]+:[0-9]+ \[ *[0-9]+(?:/ *[0-9]+)?\] (%s)'
355+
% self.TESTNAME_REGEX)
355356
parser = re.finditer(regex, output, re.MULTILINE)
356357
return list(match.group(1) for match in parser)
357358

0 commit comments

Comments
 (0)