run-tests: move test shuffling and sorting into TestRunner
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Apr 2014 10:03:08 -0700
changeset 21372 3a44787e50e2
parent 21371 a10ba7870c2d
child 21373 e478a9aab533
run-tests: move test shuffling and sorting into TestRunner
tests/run-tests.py
--- a/tests/run-tests.py	Sun Apr 20 10:00:59 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 10:03:08 2014 -0700
@@ -1019,6 +1019,25 @@
         return self._run(tests)
 
     def _run(self, tests):
+        if self.options.random:
+            random.shuffle(tests)
+        else:
+            # keywords for slow tests
+            slow = 'svn gendoc check-code-hg'.split()
+            def sortkey(f):
+                # run largest tests first, as they tend to take the longest
+                try:
+                    val = -os.stat(f).st_size
+                except OSError, e:
+                    if e.errno != errno.ENOENT:
+                        raise
+                    return -1e9 # file does not exist, tell early
+                for kw in slow:
+                    if kw in f:
+                        val *= 10
+                return val
+            tests.sort(key=sortkey)
+
         self.testdir = os.environ['TESTDIR'] = os.getcwd()
 
         if 'PYTHONHASHSEED' not in os.environ:
@@ -1444,25 +1463,6 @@
 
     tests = runner.findtests(args)
 
-    if options.random:
-        random.shuffle(tests)
-    else:
-        # keywords for slow tests
-        slow = 'svn gendoc check-code-hg'.split()
-        def sortkey(f):
-            # run largest tests first, as they tend to take the longest
-            try:
-                val = -os.stat(f).st_size
-            except OSError, e:
-                if e.errno != errno.ENOENT:
-                    raise
-                return -1e9 # file does not exist, tell early
-            for kw in slow:
-                if kw in f:
-                    val *= 10
-            return val
-        tests.sort(key=sortkey)
-
     return runner.run(tests)
 
 if __name__ == '__main__':