Issue #25220: Enhance regrtest --coverage

Add a new Regrtest.run_test() method to ensure that --coverage pass the same
options to the runtest() function.
This commit is contained in:
Victor Stinner 2015-09-29 23:36:27 +02:00
parent 56e05dd0b0
commit bd1a72c455
1 changed files with 18 additions and 10 deletions

View File

@ -346,7 +346,18 @@ class Regrtest:
print(count(len(self.bad), 'test'), "failed again:") print(count(len(self.bad), 'test'), "failed again:")
printlist(self.bad) printlist(self.bad)
def _run_tests_sequential(self): def run_test(self, test):
result = runtest(test,
self.ns.verbose,
self.ns.quiet,
self.ns.huntrleaks,
output_on_failure=self.ns.verbose3,
timeout=self.ns.timeout,
failfast=self.ns.failfast,
match_tests=self.ns.match_tests)
self.accumulate_result(test, result)
def run_tests_sequential(self):
save_modules = sys.modules.keys() save_modules = sys.modules.keys()
for test_index, test in enumerate(self.tests, 1): for test_index, test in enumerate(self.tests, 1):
@ -354,19 +365,15 @@ class Regrtest:
if self.ns.trace: if self.ns.trace:
# If we're tracing code coverage, then we don't exit with status # If we're tracing code coverage, then we don't exit with status
# if on a false return value from main. # if on a false return value from main.
cmd = 'runtest(test, self.ns.verbose, self.ns.quiet, timeout=self.ns.timeout)' cmd = 'self.run_test(test)'
self.tracer.runctx(cmd, globals=globals(), locals=vars()) self.tracer.runctx(cmd, globals=globals(), locals=vars())
else: else:
try: try:
result = runtest(test, self.ns.verbose, self.ns.quiet, self.run_test(test)
self.ns.huntrleaks,
output_on_failure=self.ns.verbose3,
timeout=self.ns.timeout, failfast=self.ns.failfast,
match_tests=self.ns.match_tests)
self.accumulate_result(test, result)
except KeyboardInterrupt: except KeyboardInterrupt:
self.interrupted = True self.interrupted = True
break break
if self.ns.findleaks: if self.ns.findleaks:
gc.collect() gc.collect()
if gc.garbage: if gc.garbage:
@ -376,13 +383,14 @@ class Regrtest:
# them again # them again
self.found_garbage.extend(gc.garbage) self.found_garbage.extend(gc.garbage)
del gc.garbage[:] del gc.garbage[:]
# Unload the newly imported modules (best effort finalization) # Unload the newly imported modules (best effort finalization)
for module in sys.modules.keys(): for module in sys.modules.keys():
if module not in save_modules and module.startswith("test."): if module not in save_modules and module.startswith("test."):
support.unload(module) support.unload(module)
def run_tests(self): def run_tests(self):
support.verbose = self.ns.verbose # Tell tests to be moderately quiet support.verbose = self.ns.verbose # Tell tests to be moderately quiet
support.use_resources = self.ns.use_resources support.use_resources = self.ns.use_resources
if self.ns.forever: if self.ns.forever:
@ -404,7 +412,7 @@ class Regrtest:
from test.libregrtest.runtest_mp import run_tests_multiprocess from test.libregrtest.runtest_mp import run_tests_multiprocess
run_tests_multiprocess(self) run_tests_multiprocess(self)
else: else:
self._run_tests_sequential() self.run_tests_sequential()
def finalize(self): def finalize(self):
if self.next_single_filename: if self.next_single_filename: