Issue #25220, libregrtest: Pass directly ns to runtest()

* Remove runtest_ns(): pass directly ns to runtest().
* Create also Regrtest.rerun_failed_tests() method.
* Inline again Regrtest.run_test(): it's no more justified to have a method
This commit is contained in:
Victor Stinner 2015-09-30 02:32:11 +02:00
parent a204502dbf
commit 6f20a2e01f
3 changed files with 44 additions and 45 deletions

View File

@ -7,7 +7,7 @@ import sysconfig
import tempfile
import textwrap
from test.libregrtest.runtest import (
findtests, runtest_ns,
findtests, runtest,
STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED)
from test.libregrtest.cmdline import _parse_args
from test.libregrtest.setup import setup_tests
@ -208,6 +208,30 @@ class Regrtest:
print("Using random seed", self.ns.random_seed)
random.shuffle(self.selected)
def rerun_failed_tests(self):
self.ns.verbose = True
self.ns.failfast = False
self.ns.verbose3 = False
self.ns.match_tests = None
print("Re-running failed tests in verbose mode")
for test in self.bad[:]:
print("Re-running test %r in verbose mode" % test, flush=True)
try:
self.ns.verbose = True
ok = runtest(self.ns, test)
except KeyboardInterrupt:
# print a newline separate from the ^C
print()
break
else:
if ok[0] in {PASSED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED}:
self.bad.remove(test)
else:
if self.bad:
print(count(len(self.bad), 'test'), "failed again:")
printlist(self.bad)
def display_result(self):
if self.interrupted:
# print a newline after ^C
@ -245,32 +269,6 @@ class Regrtest:
print(count(len(self.skipped), "test"), "skipped:")
printlist(self.skipped)
if self.ns.verbose2 and self.bad:
print("Re-running failed tests in verbose mode")
for test in self.bad[:]:
print("Re-running test %r in verbose mode" % test, flush=True)
try:
self.ns.verbose = True
ok = runtest_ns(test, True, self.ns)
except KeyboardInterrupt:
# print a newline separate from the ^C
print()
break
else:
if ok[0] in {PASSED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED}:
self.bad.remove(test)
else:
if self.bad:
print(count(len(self.bad), 'test'), "failed again:")
printlist(self.bad)
def run_test(self, test):
result = runtest_ns(test, self.ns.verbose, self.ns,
output_on_failure=self.ns.verbose3,
failfast=self.ns.failfast,
match_tests=self.ns.match_tests)
self.accumulate_result(test, result)
def run_tests_sequential(self):
if self.ns.trace:
import trace
@ -286,11 +284,13 @@ class Regrtest:
if self.tracer:
# If we're tracing code coverage, then we don't exit with status
# if on a false return value from main.
cmd = 'self.run_test(test)'
cmd = ('result = runtest(self.ns, test); '
'self.accumulate_result(test, result)')
self.tracer.runctx(cmd, globals=globals(), locals=vars())
else:
try:
self.run_test(test)
result = runtest(self.ns, test)
self.accumulate_result(test, result)
except KeyboardInterrupt:
self.interrupted = True
break
@ -366,6 +366,10 @@ class Regrtest:
self.run_tests()
self.display_result()
if self.ns.verbose2 and self.bad:
self.rerun_failed_tests()
self.finalize()
sys.exit(len(self.bad) > 0 or self.interrupted)

View File

@ -53,17 +53,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
return stdtests + sorted(tests)
def runtest_ns(test, verbose, ns, **kw):
return runtest(test, verbose, ns.quiet,
huntrleaks=ns.huntrleaks,
timeout=ns.timeout,
**kw)
def runtest(test, verbose, quiet,
huntrleaks=False,
output_on_failure=False, failfast=False, match_tests=None,
timeout=None):
def runtest(ns, test):
"""Run a single test.
test -- the name of the test
@ -85,6 +75,14 @@ def runtest(test, verbose, quiet,
PASSED test passed
"""
verbose = ns.verbose
quiet = ns.quiet
huntrleaks = ns.huntrleaks
output_on_failure = ns.verbose3
failfast = ns.failfast
match_tests = ns.match_tests
timeout = ns.timeout
use_timeout = (timeout is not None)
if use_timeout:
faulthandler.dump_traceback_later(timeout, exit=True)

View File

@ -13,7 +13,7 @@ except ImportError:
print("Multiprocess option requires thread support")
sys.exit(2)
from test.libregrtest.runtest import runtest_ns, INTERRUPTED, CHILD_ERROR
from test.libregrtest.runtest import runtest, INTERRUPTED, CHILD_ERROR
from test.libregrtest.setup import setup_tests
@ -62,10 +62,7 @@ def run_tests_slave(slaveargs):
setup_tests(ns)
try:
result = runtest_ns(testname, ns.verbose, ns,
output_on_failure=ns.verbose3,
failfast=ns.failfast,
match_tests=ns.match_tests)
result = runtest(ns, testname)
except KeyboardInterrupt:
result = INTERRUPTED, ''
except BaseException as e: