|
23 | 23 | import gc
|
24 | 24 | import logging
|
25 | 25 | import os
|
| 26 | +import random |
26 | 27 | import re
|
27 | 28 | import sys
|
28 | 29 | import unittest
|
|
55 | 56 | ARGS.add_argument(
|
56 | 57 | '--findleaks', action='store_true', dest='findleaks',
|
57 | 58 | help='detect tests that leak memory')
|
| 59 | +ARGS.add_argument('-r', '--randomize', action='store_true', |
| 60 | + help='randomize test execution order.') |
| 61 | +ARGS.add_argument('--seed', type=int, |
| 62 | + help='random seed to reproduce a previous random run') |
58 | 63 | ARGS.add_argument(
|
59 | 64 | '-q', action="store_true", dest='quiet', help='quiet')
|
60 | 65 | ARGS.add_argument(
|
@@ -112,6 +117,14 @@ def list_dir(prefix, dir):
|
112 | 117 | return mods
|
113 | 118 |
|
114 | 119 |
|
| 120 | +def randomize_tests(tests, seed): |
| 121 | + if seed is None: |
| 122 | + seed = random.randrange(10000000) |
| 123 | + random.seed(seed) |
| 124 | + print("Using random seed", seed) |
| 125 | + random.shuffle(tests._tests) |
| 126 | + |
| 127 | + |
115 | 128 | class TestsFinder:
|
116 | 129 |
|
117 | 130 | def __init__(self, testsdir, includes=(), excludes=()):
|
@@ -253,12 +266,16 @@ def runtests():
|
253 | 266 | if args.forever:
|
254 | 267 | while True:
|
255 | 268 | tests = finder.load_tests()
|
| 269 | + if args.randomize: |
| 270 | + randomize_tests(tests, args.seed) |
256 | 271 | result = runner_factory(verbosity=v,
|
257 | 272 | failfast=failfast).run(tests)
|
258 | 273 | if not result.wasSuccessful():
|
259 | 274 | sys.exit(1)
|
260 | 275 | else:
|
261 | 276 | tests = finder.load_tests()
|
| 277 | + if args.randomize: |
| 278 | + randomize_tests(tests, args.seed) |
262 | 279 | result = runner_factory(verbosity=v,
|
263 | 280 | failfast=failfast).run(tests)
|
264 | 281 | sys.exit(not result.wasSuccessful())
|
|
0 commit comments