summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-30 00:32:11 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-30 00:32:11 (GMT)
commit6f20a2e01ffe897c20d0085f63371c467d118dac (patch)
treefa0e6cdca499facca1dbc852bfea7566e83b4ff1 /Lib
parenta204502dbf38318ea926eeccab886dcb52305a16 (diff)
downloadcpython-6f20a2e01ffe897c20d0085f63371c467d118dac.zip
cpython-6f20a2e01ffe897c20d0085f63371c467d118dac.tar.gz
cpython-6f20a2e01ffe897c20d0085f63371c467d118dac.tar.bz2
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
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/libregrtest/main.py62
-rw-r--r--Lib/test/libregrtest/runtest.py20
-rw-r--r--Lib/test/libregrtest/runtest_mp.py7
3 files changed, 44 insertions, 45 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index 9ca407a..c102ee0 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -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)
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
index a3d4e79..4cc2588 100644
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -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)
diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py
index 8332a0b..df075c1 100644
--- a/Lib/test/libregrtest/runtest_mp.py
+++ b/Lib/test/libregrtest/runtest_mp.py
@@ -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: