[2.7] bpo-30283: Backport test_regrtest from master to 2.7 (#1513) · python/cpython@d2aff60 (original) (raw)
`@@ -60,6 +60,8 @@
`
60
60
` -- call gc.set_threshold(THRESHOLD)
`
61
61
`-F/--forever -- run the specified tests in a loop, until an error happens
`
62
62
`-P/--pgo -- enable Profile Guided Optimization training
`
``
63
`+
--testdir -- execute test files in the specified directory
`
``
64
`+
(instead of the Python stdlib test suite)
`
63
65
``
64
66
``
65
67
`Additional Option Details:
`
`@@ -276,7 +278,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
`
276
278
`'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
`
277
279
`'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
`
278
280
`'multiprocess=', 'slaveargs=', 'forever', 'header', 'pgo',
`
279
``
`-
'failfast', 'match='])
`
``
281
`+
'failfast', 'match=', 'testdir='])
`
280
282
`except getopt.error, msg:
`
281
283
`usage(2, msg)
`
282
284
``
`@@ -285,6 +287,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
`
285
287
`random_seed = random.randrange(10000000)
`
286
288
`if use_resources is None:
`
287
289
`use_resources = []
`
``
290
`+
slaveargs = None
`
288
291
`for o, a in opts:
`
289
292
`if o in ('-h', '--help'):
`
290
293
`usage(0)
`
`@@ -367,16 +370,11 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
`
367
370
`elif o == '--header':
`
368
371
`header = True
`
369
372
`elif o == '--slaveargs':
`
370
``
`-
args, kwargs = json.loads(a)
`
371
``
`-
try:
`
372
``
`-
result = runtest(*args, **kwargs)
`
373
``
`-
except BaseException, e:
`
374
``
`-
result = INTERRUPTED, e.class.name
`
375
``
`-
print # Force a newline (just in case)
`
376
``
`-
print json.dumps(result)
`
377
``
`-
sys.exit(0)
`
``
373
`+
slaveargs = a
`
378
374
`elif o in ('-P', '--pgo'):
`
379
375
`pgo = True
`
``
376
`+
elif o in ('--testdir'):
`
``
377
`+
testdir = a
`
380
378
`else:
`
381
379
`print >>sys.stderr, ("No handler for option {}. Please "
`
382
380
`"report this as a bug at http://bugs.python.org.").format(o)
`
`@@ -390,6 +388,25 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
`
390
388
`if failfast and not (verbose or verbose3):
`
391
389
`usage("-G/--failfast needs either -v or -W")
`
392
390
``
``
391
`+
if testdir:
`
``
392
`+
testdir = os.path.abspath(testdir)
`
``
393
+
``
394
`+
Prepend test directory to sys.path, so runtest() will be able
`
``
395
`+
to locate tests
`
``
396
`+
sys.path.insert(0, testdir)
`
``
397
+
``
398
`+
if slaveargs is not None:
`
``
399
`+
args, kwargs = json.loads(slaveargs)
`
``
400
`+
if testdir:
`
``
401
`+
kwargs['testdir'] = testdir
`
``
402
`+
try:
`
``
403
`+
result = runtest(*args, **kwargs)
`
``
404
`+
except BaseException, e:
`
``
405
`+
result = INTERRUPTED, e.class.name
`
``
406
`+
print # Force a newline (just in case)
`
``
407
`+
print json.dumps(result)
`
``
408
`+
sys.exit(0)
`
``
409
+
393
410
`good = []
`
394
411
`bad = []
`
395
412
`skipped = []
`
`@@ -544,10 +561,13 @@ def work():
`
544
561
`output.put((None, None, None, None))
`
545
562
`return
`
546
563
`# -E is needed by some tests, e.g. test_import
`
547
``
`-
popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)],
`
548
``
`-
stdout=PIPE, stderr=PIPE,
`
549
``
`-
universal_newlines=True,
`
550
``
`-
close_fds=(os.name != 'nt'))
`
``
564
`+
args = base_cmd + ['--slaveargs', json.dumps(args_tuple)]
`
``
565
`+
if testdir:
`
``
566
`+
args.extend(('--testdir', testdir))
`
``
567
`+
popen = Popen(args,
`
``
568
`+
stdout=PIPE, stderr=PIPE,
`
``
569
`+
universal_newlines=True,
`
``
570
`+
close_fds=(os.name != 'nt'))
`
551
571
`stdout, stderr = popen.communicate()
`
552
572
`retcode = popen.wait()
`
553
573
``
`@@ -616,18 +636,20 @@ def work():
`
616
636
`if trace:
`
617
637
`# If we're tracing code coverage, then we don't exit with status
`
618
638
`# if on a false return value from main.
`
619
``
`-
tracer.runctx('runtest(test, verbose, quiet)',
`
``
639
`+
tracer.runctx('runtest(test, verbose, quiet, testdir=testdir)',
`
620
640
`globals=globals(), locals=vars())
`
621
641
`else:
`
622
642
`try:
`
623
643
`result = runtest(test, verbose, quiet, huntrleaks, None, pgo,
`
624
644
`failfast=failfast,
`
625
``
`-
match_tests=match_tests)
`
``
645
`+
match_tests=match_tests,
`
``
646
`+
testdir=testdir)
`
626
647
`accumulate_result(test, result)
`
627
648
`if verbose3 and result[0] == FAILED:
`
628
649
`if not pgo:
`
629
650
`print "Re-running test %r in verbose mode" % test
`
630
``
`-
runtest(test, True, quiet, huntrleaks, None, pgo)
`
``
651
`+
runtest(test, True, quiet, huntrleaks, None, pgo,
`
``
652
`+
testdir=testdir)
`
631
653
`except KeyboardInterrupt:
`
632
654
`interrupted = True
`
633
655
`break
`
`@@ -695,7 +717,8 @@ def work():
`
695
717
`sys.stdout.flush()
`
696
718
`try:
`
697
719
`test_support.verbose = True
`
698
``
`-
ok = runtest(test, True, quiet, huntrleaks, None, pgo)
`
``
720
`+
ok = runtest(test, True, quiet, huntrleaks, None, pgo,
`
``
721
`+
testdir=testdir)
`
699
722
`except KeyboardInterrupt:
`
700
723
`# print a newline separate from the ^C
`
701
724
`
`@@ -757,7 +780,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
`
757
780
``
758
781
`def runtest(test, verbose, quiet,
`
759
782
`huntrleaks=False, use_resources=None, pgo=False,
`
760
``
`-
failfast=False, match_tests=None):
`
``
783
`+
failfast=False, match_tests=None, testdir=None):
`
761
784
`"""Run a single test.
`
762
785
``
763
786
` test -- the name of the test
`
`@@ -786,7 +809,7 @@ def runtest(test, verbose, quiet,
`
786
809
`test_support.match_tests = match_tests
`
787
810
`if failfast:
`
788
811
`test_support.failfast = True
`
789
``
`-
return runtest_inner(test, verbose, quiet, huntrleaks, pgo)
`
``
812
`+
return runtest_inner(test, verbose, quiet, huntrleaks, pgo, testdir)
`
790
813
`finally:
`
791
814
`cleanup_test_droppings(test, verbose)
`
792
815
``
`@@ -947,7 +970,7 @@ def exit(self, exc_type, exc_val, exc_tb):
`
947
970
`return False
`
948
971
``
949
972
``
950
``
`-
def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False):
`
``
973
`+
def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False, testdir=None):
`
951
974
`test_support.unload(test)
`
952
975
`if verbose:
`
953
976
`capture_stdout = None
`
`@@ -961,7 +984,7 @@ def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False):
`
961
984
`try:
`
962
985
`if capture_stdout:
`
963
986
`sys.stdout = capture_stdout
`
964
``
`-
if test.startswith('test.'):
`
``
987
`+
if test.startswith('test.') or testdir:
`
965
988
`abstest = test
`
966
989
`else:
`
967
990
`# Always import it from the test package
`
`@@ -970,7 +993,10 @@ def runtest_inner(test, verbose, quiet, huntrleaks=False, pgo=False):
`
970
993
`with saved_test_environment(test, verbose, quiet, pgo) as environment:
`
971
994
`start_time = time.time()
`
972
995
`the_package = import(abstest, globals(), locals(), [])
`
973
``
`-
the_module = getattr(the_package, test)
`
``
996
`+
if abstest.startswith('test.'):
`
``
997
`+
the_module = getattr(the_package, test)
`
``
998
`+
else:
`
``
999
`+
the_module = the_package
`
974
1000
`# Old tests run to completion simply as a side-effect of
`
975
1001
`# being imported. For tests based on unittest or doctest,
`
976
1002
`# explicitly invoke their test_main() function (if it exists).
`