Skip to content

Commit a5bb624

Browse files
authored
[2.7] bpo-30283: regrtest: backport test_slow_interrupted() and test_coverage() (#1541)
* bpo-30283: regrtest: backport test_coverage() * Add --coverage option, the option was already described in the doc * When coverage is used, regrtest now pass all options to runtest() and calls also accumulate_result() (as done when coverage is not used). * bpo-25260: Fix coverage on Windows: remove the list of ignored directories. * bpo-30283: regrtest: backport test_slow_interrupted() * Fix regrtest to report interrupted tests as omitted rather than failed. * bpo-25260: Fix coverage on Windows: remove the list of ignored directories. * bpo-30283: Fix test_regrtest on Visual Studio 2008 Skip Tools\buildbot\test.bat and PCbuild\rt.bat if Python was not compiled in PCbuild (but compiled in PC\VS9.0\ for example).
1 parent 3837d97 commit a5bb624

File tree

2 files changed

+75
-25
lines changed

2 files changed

+75
-25
lines changed

‎Lib/test/regrtest.py‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
316316
'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
317317
'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
318318
'multiprocess=', 'slaveargs=', 'forever', 'header', 'pgo',
319-
'failfast', 'match=', 'testdir=', 'list-tests'])
319+
'failfast', 'match=', 'testdir=', 'list-tests', 'coverage'])
320320
except getopt.error, msg:
321321
usage(2, msg)
322322

@@ -531,8 +531,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
531531

532532
if trace:
533533
import trace
534-
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
535-
trace=False, count=True)
534+
tracer = trace.Trace(trace=False, count=True)
536535

537536
test_times = []
538537
test_support.use_resources = use_resources
@@ -544,7 +543,7 @@ def accumulate_result(test, result):
544543
test_times.append((test_time, test))
545544
if ok == PASSED:
546545
good.append(test)
547-
elif ok == FAILED:
546+
elif ok in (FAILED, CHILD_ERROR):
548547
bad.append(test)
549548
elif ok == ENV_CHANGED:
550549
environment_changed.append(test)
@@ -553,9 +552,8 @@ def accumulate_result(test, result):
553552
elif ok == RESOURCE_DENIED:
554553
skipped.append(test)
555554
resource_denieds.append(test)
556-
else:
557-
# CHILD_ERROR
558-
bad.append(test)
555+
elif ok != INTERRUPTED:
556+
raise ValueError("invalid test result: %r" % ok)
559557

560558
if forever:
561559
def test_forever(tests=list(selected)):
@@ -740,19 +738,26 @@ def get_running(workers):
740738
if previous_test:
741739
text = '%s -- %s' % (text, previous_test)
742740
display_progress(test_index, text)
741+
742+
def local_runtest():
743+
result = runtest(test, verbose, quiet, huntrleaks, None, pgo,
744+
failfast=failfast,
745+
match_tests=match_tests,
746+
testdir=testdir)
747+
accumulate_result(test, result)
748+
return result
749+
750+
start_time = time.time()
743751
if trace:
744752
# If we're tracing code coverage, then we don't exit with status
745753
# if on a false return value from main.
746-
tracer.runctx('runtest(test, verbose, quiet, testdir=testdir)',
747-
globals=globals(), locals=vars())
754+
ns = dict(locals())
755+
tracer.runctx('result = local_runtest()',
756+
globals=globals(), locals=ns)
757+
result = ns['result']
748758
else:
749-
start_time = time.time()
750759
try:
751-
result = runtest(test, verbose, quiet, huntrleaks, None, pgo,
752-
failfast=failfast,
753-
match_tests=match_tests,
754-
testdir=testdir)
755-
accumulate_result(test, result)
760+
result = local_runtest()
756761
if verbose3 and result[0] == FAILED:
757762
if not pgo:
758763
print "Re-running test %r in verbose mode" % test
@@ -764,14 +769,14 @@ def get_running(workers):
764769
except:
765770
raise
766771

767-
previous_test = format_test_result(test, result[0])
768-
test_time = time.time() - start_time
769-
if test_time >= PROGRESS_MIN_TIME:
770-
previous_test = "%s in %s" % (previous_test,
771-
format_duration(test_time))
772-
elif result[0] == PASSED:
773-
# be quiet: say nothing if the test passed shortly
774-
previous_test = None
772+
test_time = time.time() - start_time
773+
previous_test = format_test_result(test, result[0])
774+
if test_time >= PROGRESS_MIN_TIME:
775+
previous_test = "%s in %s" % (previous_test,
776+
format_duration(test_time))
777+
elif result[0] == PASSED:
778+
# be quiet: say nothing if the test passed shortly
779+
previous_test = None
775780

776781
if findleaks:
777782
gc.collect()

‎Lib/test/test_regrtest.py‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,22 @@ def run_batch(self, *args):
255255
proc = self.run_command(args)
256256
self.check_output(proc.stdout)
257257

258-
@unittest.skipUnless(sysconfig.is_python_build(),
259-
'test.bat script is not installed')
258+
def need_pcbuild(self):
259+
exe = os.path.normpath(os.path.abspath(sys.executable))
260+
parts = exe.split(os.path.sep)
261+
if len(parts) < 3:
262+
# it's not a python build, python is likely to be installed
263+
return
264+
265+
build_dir = parts[-3]
266+
if build_dir.lower() != 'pcbuild':
267+
self.skipTest("Tools/buildbot/test.bat requires PCbuild build, "
268+
"found %s" % build_dir)
269+
260270
@unittest.skipUnless(sys.platform == 'win32', 'Windows only')
261271
def test_tools_buildbot_test(self):
272+
self.need_pcbuild()
273+
262274
# Tools\buildbot\test.bat
263275
script = os.path.join(ROOT_DIR, 'Tools', 'buildbot', 'test.bat')
264276
test_args = ['--testdir=%s' % self.tmptestdir]
@@ -272,6 +284,8 @@ def test_tools_buildbot_test(self):
272284

273285
@unittest.skipUnless(sys.platform == 'win32', 'Windows only')
274286
def test_pcbuild_rt(self):
287+
self.need_pcbuild()
288+
275289
# PCbuild\rt.bat
276290
script = os.path.join(ROOT_DIR, r'PCbuild\rt.bat')
277291
rt_args = ["-q"] # Quick, don't run tests twice
@@ -392,6 +406,37 @@ def test_slowest(self):
392406
% (self.TESTNAME_REGEX, len(tests)))
393407
self.check_line(output, regex)
394408

409+
def test_slow_interrupted(self):
410+
# Issue #25373: test --slowest with an interrupted test
411+
code = TEST_INTERRUPTED
412+
test = self.create_test("sigint", code=code)
413+
414+
try:
415+
import threading
416+
tests = (False, True)
417+
except ImportError:
418+
tests = (False,)
419+
for multiprocessing in tests:
420+
if multiprocessing:
421+
args = ("--slowest", "-j2", test)
422+
else:
423+
args = ("--slowest", test)
424+
output = self.run_tests(*args, exitcode=1)
425+
self.check_executed_tests(output, test,
426+
omitted=test, interrupted=True)
427+
428+
regex = ('10 slowest tests:\n')
429+
self.check_line(output, regex)
430+
431+
def test_coverage(self):
432+
# test --coverage
433+
test = self.create_test('coverage')
434+
output = self.run_tests("--coverage", test)
435+
self.check_executed_tests(output, [test])
436+
regex = (r'lines +cov% +module +\(path\)\n'
437+
r'(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
438+
self.check_line(output, regex)
439+
395440
def test_forever(self):
396441
# test --forever
397442
code = textwrap.dedent("""

0 commit comments

Comments
 (0)