mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
234cbef39f
commit
8bb19f094b
|
@ -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,12 +265,8 @@ class Regrtest:
|
|||
printlist(self.bad)
|
||||
|
||||
def run_test(self, test):
|
||||
result = runtest(test,
|
||||
self.ns.verbose,
|
||||
self.ns.quiet,
|
||||
self.ns.huntrleaks,
|
||||
result = runtest_ns(test, self.ns.verbose, self.ns,
|
||||
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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue