summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-29 23:32:39 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-29 23:32:39 (GMT)
commit8bb19f094ba6ba12f70a6458729c911d93c85209 (patch)
tree97a654402c7c812e1afd50520e53e858bd6e48e9 /Lib
parent234cbef39fe7f154d46afcc6fe865db2e120bba2 (diff)
downloadcpython-8bb19f094ba6ba12f70a6458729c911d93c85209.zip
cpython-8bb19f094ba6ba12f70a6458729c911d93c85209.tar.gz
cpython-8bb19f094ba6ba12f70a6458729c911d93c85209.tar.bz2
Issue #25220, libregrtest: Add runtest_ns() function
* Factorize code to run tests. * run_test_in_subprocess() now pass the whole "ns" namespace to the child process.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/libregrtest/main.py17
-rw-r--r--Lib/test/libregrtest/runtest.py7
-rw-r--r--Lib/test/libregrtest/runtest_mp.py24
3 files changed, 26 insertions, 22 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index fbbfa73..df2329f 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,
+ findtests, runtest_ns,
STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED)
from test.libregrtest.cmdline import _parse_args
from test.libregrtest.setup import setup_python
@@ -251,8 +251,7 @@ class Regrtest:
print("Re-running test %r in verbose mode" % test, flush=True)
try:
self.ns.verbose = True
- ok = runtest(test, True, self.ns.quiet, self.ns.huntrleaks,
- timeout=self.ns.timeout)
+ ok = runtest_ns(test, True, self.ns)
except KeyboardInterrupt:
# print a newline separate from the ^C
print()
@@ -266,14 +265,10 @@ class Regrtest:
printlist(self.bad)
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)
+ 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):
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
index f57784d..fb7f821 100644
--- a/Lib/test/libregrtest/runtest.py
+++ b/Lib/test/libregrtest/runtest.py
@@ -53,6 +53,13 @@ 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, use_resources=None,
output_on_failure=False, failfast=False, match_tests=None,
diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py
index 1a82b3d..74424c1 100644
--- a/Lib/test/libregrtest/runtest_mp.py
+++ b/Lib/test/libregrtest/runtest_mp.py
@@ -3,6 +3,7 @@ import os
import sys
import time
import traceback
+import types
import unittest
from queue import Queue
from test import support
@@ -30,14 +31,8 @@ def run_test_in_subprocess(testname, ns):
"""
from subprocess import Popen, PIPE
- args = (testname, ns.verbose, ns.quiet)
- kwargs = dict(huntrleaks=ns.huntrleaks,
- use_resources=ns.use_resources,
- output_on_failure=ns.verbose3,
- timeout=ns.timeout,
- failfast=ns.failfast,
- match_tests=ns.match_tests)
- slaveargs = (args, kwargs)
+ ns_dict = vars(ns)
+ slaveargs = (ns_dict, testname)
slaveargs = json.dumps(slaveargs)
cmd = [sys.executable, *support.args_from_interpreter_flags(),
@@ -60,11 +55,18 @@ def run_test_in_subprocess(testname, ns):
def run_tests_slave(slaveargs):
- args, kwargs = json.loads(slaveargs)
- if kwargs.get('huntrleaks'):
+ ns_dict, testname = json.loads(slaveargs)
+ ns = types.SimpleNamespace(**ns_dict)
+
+ if ns.huntrleaks:
unittest.BaseTestSuite._cleanup = False
+
try:
- result = runtest(*args, **kwargs)
+ result = runtest_ns(testname, ns.verbose, ns.quiet, ns,
+ use_resources=ns.use_resources,
+ output_on_failure=ns.verbose3,
+ failfast=ns.failfast,
+ match_tests=ns.match_tests)
except KeyboardInterrupt:
result = INTERRUPTED, ''
except BaseException as e: