Commit 8bb19f09 authored by Victor Stinner's avatar Victor Stinner

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.
parent 234cbef3
...@@ -7,7 +7,7 @@ import sysconfig ...@@ -7,7 +7,7 @@ import sysconfig
import tempfile import tempfile
import textwrap import textwrap
from test.libregrtest.runtest import ( from test.libregrtest.runtest import (
findtests, runtest, findtests, runtest_ns,
STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED) STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED)
from test.libregrtest.cmdline import _parse_args from test.libregrtest.cmdline import _parse_args
from test.libregrtest.setup import setup_python from test.libregrtest.setup import setup_python
...@@ -251,8 +251,7 @@ class Regrtest: ...@@ -251,8 +251,7 @@ class Regrtest:
print("Re-running test %r in verbose mode" % test, flush=True) print("Re-running test %r in verbose mode" % test, flush=True)
try: try:
self.ns.verbose = True self.ns.verbose = True
ok = runtest(test, True, self.ns.quiet, self.ns.huntrleaks, ok = runtest_ns(test, True, self.ns)
timeout=self.ns.timeout)
except KeyboardInterrupt: except KeyboardInterrupt:
# print a newline separate from the ^C # print a newline separate from the ^C
print() print()
...@@ -266,14 +265,10 @@ class Regrtest: ...@@ -266,14 +265,10 @@ class Regrtest:
printlist(self.bad) printlist(self.bad)
def run_test(self, test): def run_test(self, test):
result = runtest(test, result = runtest_ns(test, self.ns.verbose, self.ns,
self.ns.verbose, output_on_failure=self.ns.verbose3,
self.ns.quiet, failfast=self.ns.failfast,
self.ns.huntrleaks, match_tests=self.ns.match_tests)
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) self.accumulate_result(test, result)
def run_tests_sequential(self): def run_tests_sequential(self):
......
...@@ -53,6 +53,13 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): ...@@ -53,6 +53,13 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
return stdtests + sorted(tests) 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, def runtest(test, verbose, quiet,
huntrleaks=False, use_resources=None, huntrleaks=False, use_resources=None,
output_on_failure=False, failfast=False, match_tests=None, output_on_failure=False, failfast=False, match_tests=None,
......
...@@ -3,6 +3,7 @@ import os ...@@ -3,6 +3,7 @@ import os
import sys import sys
import time import time
import traceback import traceback
import types
import unittest import unittest
from queue import Queue from queue import Queue
from test import support from test import support
...@@ -30,14 +31,8 @@ def run_test_in_subprocess(testname, ns): ...@@ -30,14 +31,8 @@ def run_test_in_subprocess(testname, ns):
""" """
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
args = (testname, ns.verbose, ns.quiet) ns_dict = vars(ns)
kwargs = dict(huntrleaks=ns.huntrleaks, slaveargs = (ns_dict, testname)
use_resources=ns.use_resources,
output_on_failure=ns.verbose3,
timeout=ns.timeout,
failfast=ns.failfast,
match_tests=ns.match_tests)
slaveargs = (args, kwargs)
slaveargs = json.dumps(slaveargs) slaveargs = json.dumps(slaveargs)
cmd = [sys.executable, *support.args_from_interpreter_flags(), cmd = [sys.executable, *support.args_from_interpreter_flags(),
...@@ -60,11 +55,18 @@ def run_test_in_subprocess(testname, ns): ...@@ -60,11 +55,18 @@ def run_test_in_subprocess(testname, ns):
def run_tests_slave(slaveargs): def run_tests_slave(slaveargs):
args, kwargs = json.loads(slaveargs) ns_dict, testname = json.loads(slaveargs)
if kwargs.get('huntrleaks'): ns = types.SimpleNamespace(**ns_dict)
if ns.huntrleaks:
unittest.BaseTestSuite._cleanup = False unittest.BaseTestSuite._cleanup = False
try: 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: except KeyboardInterrupt:
result = INTERRUPTED, '' result = INTERRUPTED, ''
except BaseException as e: except BaseException as e:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment