Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 216a3bc

Browse files
committed
Issue #12624: It is now possible to fail after the first failure when
running in verbose mode (`-v` or `-W`), by using the `--failfast` (or `-G`) option to regrtest. This is useful with long test suites such as test_io or test_subprocess.
1 parent ab85ff3 commit 216a3bc

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

Lib/test/regrtest.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
-f/--fromfile -- read names of tests to run from a file (see below)
3939
-x/--exclude -- arguments are tests to *exclude*
4040
-s/--single -- single step through a set of tests (see below)
41+
-G/--failfast -- fail as soon as a test fails (only with -v or -W)
4142
-u/--use RES1,RES2,...
4243
-- specify which special resource intensive tests to run
4344
-M/--memlimit LIMIT
@@ -241,7 +242,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
241242
findleaks=False, use_resources=None, trace=False, coverdir='coverage',
242243
runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
243244
random_seed=None, use_mp=None, verbose3=False, forever=False,
244-
header=False):
245+
header=False, failfast=False):
245246
"""Execute a test suite.
246247
247248
This also parses command-line options and modifies its behavior
@@ -269,13 +270,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
269270

270271
support.record_original_stdout(sys.stdout)
271272
try:
272-
opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:',
273+
opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:G',
273274
['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
274275
'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
275276
'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
276277
'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
277278
'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
278-
'start=', 'nowindows', 'header'])
279+
'start=', 'nowindows', 'header', 'failfast'])
279280
except getopt.error as msg:
280281
usage(msg)
281282

@@ -298,6 +299,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
298299
debug = True
299300
elif o in ('-W', '--verbose3'):
300301
verbose3 = True
302+
elif o in ('-G', '--failfast'):
303+
failfast = True
301304
elif o in ('-q', '--quiet'):
302305
quiet = True;
303306
verbose = 0
@@ -406,6 +409,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
406409
usage("-T and -j don't go together!")
407410
if use_mp and findleaks:
408411
usage("-l and -j don't go together!")
412+
if failfast and not (verbose or verbose3):
413+
usage("-G/--failfast needs either -v or -W")
409414

410415
good = []
411416
bad = []
@@ -545,7 +550,8 @@ def tests_and_args():
545550
args_tuple = (
546551
(test, verbose, quiet),
547552
dict(huntrleaks=huntrleaks, use_resources=use_resources,
548-
debug=debug, output_on_failure=verbose3)
553+
debug=debug, output_on_failure=verbose3,
554+
failfast=failfast)
549555
)
550556
yield (test, args_tuple)
551557
pending = tests_and_args()
@@ -623,7 +629,8 @@ def work():
623629
else:
624630
try:
625631
result = runtest(test, verbose, quiet, huntrleaks, debug,
626-
output_on_failure=verbose3)
632+
output_on_failure=verbose3,
633+
failfast=failfast)
627634
accumulate_result(test, result)
628635
except KeyboardInterrupt:
629636
interrupted = True
@@ -770,7 +777,7 @@ def restore_stdout():
770777

771778
def runtest(test, verbose, quiet,
772779
huntrleaks=False, debug=False, use_resources=None,
773-
output_on_failure=False):
780+
output_on_failure=False, failfast=False):
774781
"""Run a single test.
775782
776783
test -- the name of the test
@@ -793,6 +800,8 @@ def runtest(test, verbose, quiet,
793800
if use_resources is not None:
794801
support.use_resources = use_resources
795802
try:
803+
if failfast:
804+
support.failfast = True
796805
if output_on_failure:
797806
support.verbose = True
798807

Lib/test/support.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"reap_children", "cpython_only", "check_impl_detail", "get_attribute",
5353
"swap_item", "swap_attr", "requires_IEEE_754",
5454
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
55-
"import_fresh_module"
55+
"import_fresh_module", "failfast",
5656
]
5757

5858
class Error(Exception):
@@ -176,6 +176,7 @@ def get_attribute(obj, name):
176176
max_memuse = 0 # Disable bigmem tests (they will still be run with
177177
# small sizes, to make sure they work.)
178178
real_max_memuse = 0
179+
failfast = False
179180

180181
# _original_stdout is meant to hold stdout at the time regrtest began.
181182
# This may be "the real" stdout, or IDLE's emulation of stdout, or whatever.
@@ -1186,7 +1187,8 @@ def check_impl_detail(**guards):
11861187
def _run_suite(suite):
11871188
"""Run tests from a unittest.TestSuite-derived class."""
11881189
if verbose:
1189-
runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
1190+
runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
1191+
failfast=failfast)
11901192
else:
11911193
runner = BasicTestRunner()
11921194

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ C-API
104104
Tests
105105
-----
106106

107+
- Issue #12624: It is now possible to fail after the first failure when
108+
running in verbose mode (``-v`` or ``-W``), by using the ``--failfast``
109+
(or ``-G``) option to regrtest. This is useful with long test suites
110+
such as test_io or test_subprocess.
111+
107112
- Issue #12587: Correct faulty test file and reference in test_tokenize.
108113
(Patch by Robert Xiao)
109114

0 commit comments

Comments
 (0)