]> granicus.if.org Git - python/commitdiff
Issue #25220, libregrtest: Add runtest_ns() function
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Sep 2015 23:32:39 +0000 (01:32 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Sep 2015 23:32:39 +0000 (01:32 +0200)
* Factorize code to run tests.
* run_test_in_subprocess() now pass the whole "ns" namespace to the child
  process.

Lib/test/libregrtest/main.py
Lib/test/libregrtest/runtest.py
Lib/test/libregrtest/runtest_mp.py

index fbbfa732af567adaba1cd3bb437414411e8e33d6..df2329f2d3cc45b316dc6e0999e7ed908dc17a75 100644 (file)
@@ -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):
index f57784de657c42c521bdb8817aacbde104983d34..fb7f82152ad37674c82df98d73acc548cadb8d6f 100644 (file)
@@ -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,
index 1a82b3d257637cda85227faaf075562054215916..74424c14ba2637dfee4fc1e3377124154b8b5b63 100644 (file)
@@ -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: