]> granicus.if.org Git - python/commitdiff
Issue #12626: In regrtest, allow to filter tests using a glob filter
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 29 Jul 2011 21:57:10 +0000 (23:57 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 29 Jul 2011 21:57:10 +0000 (23:57 +0200)
with the `-m` (or `--match`) option.  This works with all test cases
using the unittest module.  This is useful with long test suites
such as test_io or test_subprocess.

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

index 9bb43078e35705a634298cb102499b4938aa2b77,077434baaf73bf5319d20c82156404747d85cda0..ef8ea6d918da2ed23e25590fd9283382a539cf2f
@@@ -299,8 -277,7 +300,8 @@@ def main(tests=None, testdir=None, verb
               'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
               'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
               'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
 -             'start=', 'nowindows', 'header', 'failfast', 'match'])
 +             'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait',
-              'failfast'])
++             'failfast', 'match'])
      except getopt.error as msg:
          usage(msg)
  
                      (test, verbose, quiet),
                      dict(huntrleaks=huntrleaks, use_resources=use_resources,
                           debug=debug, output_on_failure=verbose3,
-                          timeout=timeout, failfast=failfast)
 -                         failfast=failfast, match_tests=match_tests)
++                         timeout=timeout, failfast=failfast,
++                         match_tests=match_tests)
                  )
                  yield (test, args_tuple)
          pending = tests_and_args()
                  try:
                      result = runtest(test, verbose, quiet, huntrleaks, debug,
                                       output_on_failure=verbose3,
-                                      timeout=timeout, failfast=failfast)
 -                                     failfast=failfast, match_tests=match_tests)
++                                     timeout=timeout, failfast=failfast,
++                                     match_tests=match_tests)
                      accumulate_result(test, result)
                  except KeyboardInterrupt:
                      interrupted = True
@@@ -837,7 -780,7 +842,8 @@@ def replace_stdout()
  
  def runtest(test, verbose, quiet,
              huntrleaks=False, debug=False, use_resources=None,
-             output_on_failure=False, failfast=False, timeout=None):
 -            output_on_failure=False, failfast=False, match_tests=None):
++            output_on_failure=False, failfast=False, match_tests=None,
++            timeout=None):
      """Run a single test.
  
      test -- the name of the test
  
      if use_resources is not None:
          support.use_resources = use_resources
 +    use_timeout = (timeout is not None)
 +    if use_timeout:
 +        faulthandler.dump_tracebacks_later(timeout, exit=True)
      try:
+         support.match_tests = match_tests
          if failfast:
              support.failfast = True
          if output_on_failure:
index 8a60ba995efd5bf1d21de3d4103c1cc7b8f92881,e82a4f9316d96db434c308a25d95daec99582574..64c1b4e454b5f7b63d645c0b9c7e5c9ee37f1f22
@@@ -1241,33 -1185,19 +1243,45 @@@ def check_impl_detail(**guards)
      return guards.get(platform.python_implementation().lower(), default)
  
  
 -
 +def no_tracing(func):
 +    """Decorator to temporarily turn off tracing for the duration of a test."""
 +    if not hasattr(sys, 'gettrace'):
 +        return func
 +    else:
 +        @functools.wraps(func)
 +        def wrapper(*args, **kwargs):
 +            original_trace = sys.gettrace()
 +            try:
 +                sys.settrace(None)
 +                return func(*args, **kwargs)
 +            finally:
 +                sys.settrace(original_trace)
 +        return wrapper
 +
 +
 +def refcount_test(test):
 +    """Decorator for tests which involve reference counting.
 +
 +    To start, the decorator does not run the test if is not run by CPython.
 +    After that, any trace function is unset during the test to prevent
 +    unexpected refcounts caused by the trace function.
 +
 +    """
 +    return no_tracing(cpython_only(test))
 +
 +
+ def _filter_suite(suite, pred):
+     """Recursively filter test cases in a suite based on a predicate."""
+     newtests = []
+     for test in suite._tests:
+         if isinstance(test, unittest.TestSuite):
+             _filter_suite(test, pred)
+             newtests.append(test)
+         else:
+             if pred(test):
+                 newtests.append(test)
+     suite._tests = newtests
  def _run_suite(suite):
      """Run tests from a unittest.TestSuite-derived class."""
      if verbose:
diff --cc Misc/NEWS
index 0b205ad9a8b3b54f94ffef385529cccb6bfcb487,ef432e0d29687bb479fbd117d5977ba01c95a855..5ab2d17ed6e82d18abf88569b3e12eb82e3068e2
+++ b/Misc/NEWS
@@@ -1137,86 -792,6 +1137,91 @@@ Extension Module
  Tests
  -----
  
++- Issue #12626: In regrtest, allow to filter tests using a glob filter
++  with the ``-m`` (or ``--match``) option.  This works with all test cases
++  using the unittest module.  This is useful with long test suites
++  such as test_io or test_subprocess.
++
 +- 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)
 +
 +- Issue #12573: Add resource checks for dangling Thread and Process objects.
 +
 +- Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64'
 +  as the processor type on some Mac systems.
 +
 +- Skip network tests when getaddrinfo() returns EAI_AGAIN, meaning a temporary
 +  failure in name resolution.
 +
 +- Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
 +  an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
 +  Web site.
 +
 +- Avoid failing in test_urllibnet.test_bad_address when some overzealous
 +  DNS service (e.g. OpenDNS) resolves a non-existent domain name.  The test
 +  is now skipped instead.
 +
 +- Issue #12440: When testing whether some bits in SSLContext.options can be
 +  reset, check the version of the OpenSSL headers Python was compiled against,
 +  rather than the runtime version of the OpenSSL library.
 +
 +- Issue #11512: Add a test suite for the cgitb module. Patch by Robbie Clemons.
 +
 +- Issue #12497: Install test/data to prevent failures of the various codecmaps
 +  tests.
 +
 +- Issue #12496: Install test/capath directory to prevent test_connect_capath
 +  testcase failure in test_ssl.
 +
 +- Issue #12469: Run wakeup and pending signal tests in a subprocess to run the
 +  test in a fresh process with only one thread and to not change signal
 +  handling of the parent process.
 +
 +- Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
 +  test_tk or test_ttk_guionly under a username that is not currently logged
 +  in to the console windowserver (as may be the case under buildbot or ssh).
 +
 +- Issue #12407: Explicitly skip test_capi.EmbeddingTest under Windows.
 +
 +- Issue #12400: regrtest -W doesn't rerun the tests twice anymore, but captures
 +  the output and displays it on failure instead. regrtest -v doesn't print the
 +  error twice anymore if there is only one error.
 +
 +- Issue #12141: Install copies of template C module file so that
 +  test_build_ext of test_distutils and test_command_build_ext of
 +  test_packaging are no longer silently skipped when
 +  run outside of a build directory.
 +
 +- Issue #8746: Add additional tests for os.chflags() and os.lchflags().
 +  Patch by Garrett Cooper.
 +
 +- Issue #10736: Fix test_ttk test_widgets failures with Cocoa Tk 8.5.9
 +  2.8 +  on Mac OS X.  (Patch by Ronald Oussoren)
 +
 +- Issue #12057: Add tests for ISO 2022 codecs (iso2022_jp, iso2022_jp_2,
 +  iso2022_kr).
 +
 +- Issue #12180: Fixed a few remaining errors in test_packaging when no
 +  threading.
 +
 +- Issue #12120, #12119: skip a test in packaging and distutils
 +  if sys.dont_write_bytecode is set to True.
 +
 +- Issue #12096: Fix a race condition in test_threading.test_waitfor(). Patch
 +  written by Charles-François Natali.
 +
 +- Issue #11614: import __hello__ prints "Hello World!". Patch written by
 +  Andreas Stührk.
 +
 +- Issue #5723: Improve json tests to be executed with and without accelerations.
 +
 +- Issue #12041: Make test_wait3 more robust.
 +
  - Issue #11873: Change regex in test_compileall to fix occasional failures when
    when the randomly generated temporary path happened to match the regex.