8000 Add option to randomize test order. · python/asyncio@2a0e55d · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 2a0e55d

Browse files
committed
Add option to randomize test order.
1 parent f8091e7 commit 2a0e55d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

runtests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import gc
2424
import logging
2525
import os
26+
import random
2627
import re
2728
import sys
2829
import unittest
@@ -55,6 +56,10 @@
5556
ARGS.add_argument(
5657
'--findleaks', action='store_true', dest='findleaks',
5758
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')
5863
ARGS.add_argument(
5964
'-q', action="store_true", dest='quiet', help='quiet')
6065
ARGS.add_argument(
@@ -112,6 +117,14 @@ def list_dir(prefix, dir):
112117
return mods
113118

114119

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+
115128
class TestsFinder:
116129

117130
def __init__(self, testsdir, includes=(), excludes=()):
@@ -253,12 +266,16 @@ def runtests():
253266
if args.forever:
254267
while True:
255268
tests = finder.load_tests()
269+
if args.randomize:
270+
randomize_tests(tests, args.seed)
256271
result = runner_factory(verbosity=v,
257272
failfast=failfast).run(tests)
258273
if not result.wasSuccessful():
259274
sys.exit(1)
260275
else:
261276
tests = finder.load_tests()
277+
if args.randomize:
278+
randomize_tests(tests, args.seed)
262279
result = runner_factory(verbosity=v,
263280
failfast=failfast).run(tests)
264281
sys.exit(not result.wasSuccessful())

0 commit comments

Comments
 (0)
0