summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-09-02 15:57:21 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-09-02 15:57:21 (GMT)
commit7f5c22c022592e5e9a82520e152d619f58382e7d (patch)
treee858f55cae5f52c64a728161733d4c6f48bc6bf4 /Lib
parenta35adf5b0984758ddc64ced81cfac56fa15fd94a (diff)
downloadcpython-7f5c22c022592e5e9a82520e152d619f58382e7d.zip
cpython-7f5c22c022592e5e9a82520e152d619f58382e7d.tar.gz
cpython-7f5c22c022592e5e9a82520e152d619f58382e7d.tar.bz2
Refactor the main function of regrtest a bit.
Moving subprocess execution of tests into a function.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/test/regrtest.py56
1 files changed, 33 insertions, 23 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 1f734c4..075f347 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -426,6 +426,38 @@ def _parse_args(args, **kwargs):
return ns
+def run_test_in_subprocess(testname, ns):
+ """Run the given test in a subprocess with --slaveargs.
+
+ ns is the option Namespace parsed from command-line arguments. regrtest
+ is invoked in a subprocess with the --slaveargs argument; when the
+ subprocess exits, its return code, stdout and stderr are returned as a
+ 3-tuple.
+ """
+ from subprocess import Popen, PIPE
+ base_cmd = ([sys.executable] + support.args_from_interpreter_flags() +
+ ['-X', 'faulthandler', '-m', 'test.regrtest'])
+
+ slaveargs = (
+ (testname, ns.verbose, ns.quiet),
+ dict(huntrleaks=ns.huntrleaks,
+ use_resources=ns.use_resources,
+ debug=ns.debug, output_on_failure=ns.verbose3,
+ timeout=ns.timeout, failfast=ns.failfast,
+ match_tests=ns.match_tests))
+ # Running the child from the same working directory as regrtest's original
+ # invocation ensures that TEMPDIR for the child is the same when
+ # sysconfig.is_python_build() is true. See issue 15300.
+ popen = Popen(base_cmd + ['--slaveargs', json.dumps(slaveargs)],
+ stdout=PIPE, stderr=PIPE,
+ universal_newlines=True,
+ close_fds=(os.name != 'nt'),
+ cwd=support.SAVEDCWD)
+ stdout, stderr = popen.communicate()
+ retcode = popen.wait()
+ return retcode, stdout, stderr
+
+
def main(tests=None, **kwargs):
"""Execute a test suite.
@@ -648,13 +680,9 @@ def main(tests=None, **kwargs):
print("Multiprocess option requires thread support")
sys.exit(2)
from queue import Queue
- from subprocess import Popen, PIPE
debug_output_pat = re.compile(r"\[\d+ refs, \d+ blocks\]$")
output = Queue()
pending = MultiprocessTests(tests)
- opt_args = support.args_from_interpreter_flags()
- base_cmd = [sys.executable] + opt_args
- base_cmd += ['-X', 'faulthandler', '-m', 'test.regrtest']
def work():
# A worker thread.
try:
@@ -664,25 +692,7 @@ def main(tests=None, **kwargs):
except StopIteration:
output.put((None, None, None, None))
return
- args_tuple = (
- (test, ns.verbose, ns.quiet),
- dict(huntrleaks=ns.huntrleaks,
- use_resources=ns.use_resources,
- debug=ns.debug, output_on_failure=ns.verbose3,
- timeout=ns.timeout, failfast=ns.failfast,
- match_tests=ns.match_tests)
- )
- # -E is needed by some tests, e.g. test_import
- # Running the child from the same working directory ensures
- # that TEMPDIR for the child is the same when
- # sysconfig.is_python_build() is true. See issue 15300.
- popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)],
- stdout=PIPE, stderr=PIPE,
- universal_newlines=True,
- close_fds=(os.name != 'nt'),
- cwd=support.SAVEDCWD)
- stdout, stderr = popen.communicate()
- retcode = popen.wait()
+ retcode, stdout, stderr = run_test_in_subprocess(test, ns)
# Strip last refcount output line if it exists, since it
# comes from the shutdown of the interpreter in the subcommand.
stderr = debug_output_pat.sub("", stderr)