run-tests: define a custom TestSuite that uses _executetests()
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Apr 2014 13:04:19 -0700
changeset 21439 2e22954b97e3
parent 21438 f647287b44d1
child 21440 ece127734db1
run-tests: define a custom TestSuite that uses _executetests() We now have a custom unittest.TestSuite implementation that uses _executetests() and thus knows how to execute tests concurrently. Running tests in --unittest mode will use this TestSuite. Since the TestSuite handles concurrency, the warnings around --jobs and --loop have been removed.
tests/run-tests.py
--- a/tests/run-tests.py	Sun Apr 20 13:00:40 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 13:04:19 2014 -0700
@@ -259,13 +259,6 @@
 
     if options.jobs < 1:
         parser.error('--jobs must be positive')
-    if options.unittest:
-        if options.jobs > 1:
-            sys.stderr.write(
-                'warning: --jobs has no effect with --unittest')
-        if options.loop:
-            sys.stderr.write(
-                'warning: --loop has no effect with --unittest')
     if options.interactive and options.debug:
         parser.error("-i/--interactive and -d/--debug are incompatible")
     if options.debug:
@@ -1033,6 +1026,19 @@
             self.stream.write('~')
             self.stream.flush()
 
+class TestSuite(unittest.TestSuite):
+    """Custom unitest TestSuite that knows how to execute concurrently."""
+
+    def __init__(self, runner, *args, **kwargs):
+        super(TestSuite, self).__init__(*args, **kwargs)
+
+        self._runner = runner
+
+    def run(self, result):
+        self._runner._executetests(self._tests, result=result)
+
+        return result
+
 class TextTestRunner(unittest.TextTestRunner):
     """Custom unittest test runner that uses appropriate settings."""
 
@@ -1245,7 +1251,7 @@
                      for i, t in enumerate(tests)]
 
             if self.options.unittest:
-                suite = unittest.TestSuite(tests=tests)
+                suite = TestSuite(self, tests=tests)
                 verbosity = 1
                 if self.options.verbose:
                     verbosity = 2