]> granicus.if.org Git - python/commitdiff
Issue #12624: It is now possible to fail after the first failure when
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 23 Jul 2011 20:33:39 +0000 (22:33 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 23 Jul 2011 20:33:39 +0000 (22:33 +0200)
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.

Lib/test/regrtest.py
Lib/test/support.py
Misc/NEWS

index 8ca7f6c07f8f7cfdb32d72840ae6fc08af06e7af..6fad78fc0b0991511b7e90a925edd770c3639875 100755 (executable)
@@ -38,6 +38,7 @@ Selecting tests
 -f/--fromfile   -- read names of tests to run from a file (see below)
 -x/--exclude    -- arguments are tests to *exclude*
 -s/--single     -- single step through a set of tests (see below)
+-G/--failfast   -- fail as soon as a test fails (only with -v or -W)
 -u/--use RES1,RES2,...
                 -- specify which special resource intensive tests to run
 -M/--memlimit LIMIT
@@ -241,7 +242,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
          findleaks=False, use_resources=None, trace=False, coverdir='coverage',
          runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
          random_seed=None, use_mp=None, verbose3=False, forever=False,
-         header=False):
+         header=False, failfast=False):
     """Execute a test suite.
 
     This also parses command-line options and modifies its behavior
@@ -269,13 +270,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
 
     support.record_original_stdout(sys.stdout)
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:',
+        opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:G',
             ['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
              'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
              'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
              'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
              'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
-             'start=', 'nowindows', 'header'])
+             'start=', 'nowindows', 'header', 'failfast'])
     except getopt.error as msg:
         usage(msg)
 
@@ -298,6 +299,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
             debug = True
         elif o in ('-W', '--verbose3'):
             verbose3 = True
+        elif o in ('-G', '--failfast'):
+            failfast = True
         elif o in ('-q', '--quiet'):
             quiet = True;
             verbose = 0
@@ -406,6 +409,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
         usage("-T and -j don't go together!")
     if use_mp and findleaks:
         usage("-l and -j don't go together!")
+    if failfast and not (verbose or verbose3):
+        usage("-G/--failfast needs either -v or -W")
 
     good = []
     bad = []
@@ -545,7 +550,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
                 args_tuple = (
                     (test, verbose, quiet),
                     dict(huntrleaks=huntrleaks, use_resources=use_resources,
-                         debug=debug, output_on_failure=verbose3)
+                         debug=debug, output_on_failure=verbose3,
+                         failfast=failfast)
                 )
                 yield (test, args_tuple)
         pending = tests_and_args()
@@ -623,7 +629,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
             else:
                 try:
                     result = runtest(test, verbose, quiet, huntrleaks, debug,
-                                     output_on_failure=verbose3)
+                                     output_on_failure=verbose3,
+                                     failfast=failfast)
                     accumulate_result(test, result)
                 except KeyboardInterrupt:
                     interrupted = True
@@ -770,7 +777,7 @@ def replace_stdout():
 
 def runtest(test, verbose, quiet,
             huntrleaks=False, debug=False, use_resources=None,
-            output_on_failure=False):
+            output_on_failure=False, failfast=False):
     """Run a single test.
 
     test -- the name of the test
@@ -793,6 +800,8 @@ def runtest(test, verbose, quiet,
     if use_resources is not None:
         support.use_resources = use_resources
     try:
+        if failfast:
+            support.failfast = True
         if output_on_failure:
             support.verbose = True
 
index 2827e8b84230e7209921afa16d6bfbaf1ad14fea..09846a85a2019e3dbb2fde51f2e0a1513c30724a 100644 (file)
@@ -52,7 +52,7 @@ __all__ = [
     "reap_children", "cpython_only", "check_impl_detail", "get_attribute",
     "swap_item", "swap_attr", "requires_IEEE_754",
     "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
-    "import_fresh_module"
+    "import_fresh_module", "failfast",
     ]
 
 class Error(Exception):
@@ -176,6 +176,7 @@ use_resources = None     # Flag set to [] by regrtest.py
 max_memuse = 0           # Disable bigmem tests (they will still be run with
                          # small sizes, to make sure they work.)
 real_max_memuse = 0
+failfast = False
 
 # _original_stdout is meant to hold stdout at the time regrtest began.
 # This may be "the real" stdout, or IDLE's emulation of stdout, or whatever.
@@ -1186,7 +1187,8 @@ def check_impl_detail(**guards):
 def _run_suite(suite):
     """Run tests from a unittest.TestSuite-derived class."""
     if verbose:
-        runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
+        runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
+                                         failfast=failfast)
     else:
         runner = BasicTestRunner()
 
index f6a222d0e19cca4101f44893e97c1d42935bbdf3..c7e917e045f412f1285824da316f1dcb6bb8eb04 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -104,6 +104,11 @@ C-API
 Tests
 -----
 
+- 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.
+
 - Issue #12587: Correct faulty test file and reference in test_tokenize.
   (Patch by Robert Xiao)