summaryrefslogtreecommitdiff
path: root/runtests.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2014-05-19 08:14:50 -0700
committerGuido van Rossum <guido@python.org>2014-05-19 08:14:50 -0700
commit22c6507b60624520e6fa235b95a04dcba89ce495 (patch)
treecac3a063f28e79baa779eeb72802ca946e0633c9 /runtests.py
parente86fa5426be0ca9a7ee57e6ec5b7a0fd06e80932 (diff)
downloadtrollius-22c6507b60624520e6fa235b95a04dcba89ce495.tar.gz
Add option to randomize test order.
Diffstat (limited to 'runtests.py')
-rw-r--r--runtests.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/runtests.py b/runtests.py
index 469ac86..4d06f69 100644
--- a/runtests.py
+++ b/runtests.py
@@ -23,6 +23,7 @@ import argparse
import gc
import logging
import os
+import random
import re
import sys
import unittest
@@ -55,6 +56,10 @@ ARGS.add_argument(
ARGS.add_argument(
'--findleaks', action='store_true', dest='findleaks',
help='detect tests that leak memory')
+ARGS.add_argument('-r', '--randomize', action='store_true',
+ help='randomize test execution order.')
+ARGS.add_argument('--seed', type=int,
+ help='random seed to reproduce a previous random run')
ARGS.add_argument(
'-q', action="store_true", dest='quiet', help='quiet')
ARGS.add_argument(
@@ -112,6 +117,14 @@ def load_modules(basedir, suffix='.py'):
return mods
+def randomize_tests(tests, seed):
+ if seed is None:
+ seed = random.randrange(10000000)
+ random.seed(seed)
+ print("Using random seed", seed)
+ random.shuffle(tests._tests)
+
+
class TestsFinder:
def __init__(self, testsdir, includes=(), excludes=()):
@@ -253,12 +266,16 @@ def runtests():
if args.forever:
while True:
tests = finder.load_tests()
+ if args.randomize:
+ randomize_tests(tests, args.seed)
result = runner_factory(verbosity=v,
failfast=failfast).run(tests)
if not result.wasSuccessful():
sys.exit(1)
else:
tests = finder.load_tests()
+ if args.randomize:
+ randomize_tests(tests, args.seed)
result = runner_factory(verbosity=v,
failfast=failfast).run(tests)
sys.exit(not result.wasSuccessful())