@@ -34,14 +34,14 @@ def get_versions(): # type: () -> typing.List[str]
34
34
import itertools
35
35
import os
36
36
import re
37
+ import json
37
38
38
39
39
40
# Ideally, all tests would be `discover`able so that they can be driven
40
41
# (and parallelized) by an external test driver.
41
42
42
43
class Driver :
43
-
44
- def __init__ (self , whitelist : List [str ], blacklist : List [str ],
44
+ def __init__ (self , whitelist : List [str ], blacklist : List [str ], refresh_cache : bool ,
45
45
arglist : List [str ], pyt_arglist : List [str ],
46
46
verbosity : int , parallel_limit : int ,
47
47
xfail : List [str ], coverage : bool ) -> None :
@@ -50,6 +50,9 @@ def __init__(self, whitelist: List[str], blacklist: List[str],
50
50
self .arglist = arglist
51
51
self .pyt_arglist = pyt_arglist
52
52
self .verbosity = verbosity
53
+ self .refresh_cache = refresh_cache
54
+ if self .refresh_cache :
55
+ parallel_limit = 1
53
56
self .waiter = Waiter (verbosity = verbosity , limit = parallel_limit , xfail = xfail )
54
57
self .sequential = Waiter (verbosity = verbosity , limit = 1 , xfail = xfail )
55
58
self .versions = get_versions ()
@@ -58,6 +61,10 @@ def __init__(self, whitelist: List[str], blacklist: List[str],
58
61
self .env = dict (os .environ )
59
62
self .coverage = coverage
60
63
64
+ def run (self ) -> int :
65
+ exit_code = self .sequential .run () & self .waiter .run ()
66
+ return exit_code
67
+
61
68
def prepend_path (self , name : str , paths : List [str ]) -> None :
62
69
old_val = self .env .get (name )
63
70
paths = [p for p in paths if isdir (p )]
@@ -300,7 +307,8 @@ def add_samples(driver: Driver) -> None:
300
307
301
308
302
309
def usage (status : int ) -> None :
303
- print ('Usage: %s [-h | -v | -q | [-x] FILTER | -a ARG | -p ARG] ... [-- FILTER ...]'
310
+ print ('Usage: %s [-h | -v | -q | --lf | --ff | [-x] FILTER | -a ARG | -p ARG]'
311
+ '... [-- FILTER ...]'
304
312
% sys .argv [0 ])
305
313
print ()
306
314
print ('Run mypy tests. If given no arguments, run all tests.' )
@@ -313,6 +321,12 @@ def usage(status: int) -> None:
313
321
print ('Options:' )
314
322
print (' -h, --help show this help' )
315
323
print (' -v, --verbose increase driver verbosity' )
324
+ print (' --lf rerun only the tests that failed at the last run '
325
+ '(or all if none failed)' )
326
+ print (' --lf run all tests but run the last failures first. This '
327
+ 'may re-order tests and thus lead to repeated fixture '
328
+ 'setup/teardown' )
329
+ print (' -v, --verbose increase driver verbosity' )
316
330
print (' -q, --quiet decrease driver verbosity' )
317
331
print (' -jN run N tasks at once (default: one per CPU)' )
318
332
print (' -a, --argument ARG pass an argument to myunit tasks' )
@@ -322,6 +336,7 @@ def usage(status: int) -> None:
322
336
print (' FILTER include tasks matching FILTER' )
323
337
print (' -x, --exclude FILTER exclude tasks matching FILTER' )
324
338
print (' -c, --coverage calculate code coverage while running tests' )
339
+ print (' -r, --refresh-cache refresh timing information' )
325
340
print (' -- treat all remaining arguments as positional' )
326
341
sys .exit (status )
327
342
@@ -353,6 +368,7 @@ def main() -> None:
353
368
arglist = [] # type: List[str]
354
369
pyt_arglist = [] # type: List[str]
355
370
list_only = False
371
+ refresh_cache = False
356
372
coverage = False
357
373
358
374
allow_opts = True
@@ -382,6 +398,8 @@ def main() -> None:
382
398
list_only = True
383
399
elif a == '-c' or a == '--coverage' :
384
400
coverage = True
401
+ elif a == '-r' or a == '--refresh-cache' :
402
+ refresh_cache = True
385
403
elif a == '-h' or a == '--help' :
386
404
usage (0 )
387
405
else :
@@ -399,7 +417,7 @@ def main() -> None:
399
417
if not whitelist :
400
418
whitelist .append ('' )
401
419
402
- driver = Driver (whitelist = whitelist , blacklist = blacklist ,
420
+ driver = Driver (whitelist = whitelist , blacklist = blacklist , refresh_cache = refresh_cache ,
403
421
arglist = arglist , pyt_arglist = pyt_arglist , verbosity = verbosity ,
404
422
parallel_limit = parallel_limit , xfail = [], coverage = coverage )
405
423
@@ -424,7 +442,7 @@ def main() -> None:
424
442
driver .list_tasks ()
425
443
return
426
444
427
- exit_code = driver .sequential . run () & driver . waiter . run ()
445
+ exit_code = driver .run ()
428
446
t1 = time .perf_counter ()
429
447
print ('total runtime:' , t1 - t0 , 'sec' )
430
448
0 commit comments