From: Antoine Pitrou Date: Fri, 29 Jul 2011 21:57:10 +0000 (+0200) Subject: Issue #12626: In regrtest, allow to filter tests using a glob filter X-Git-Tag: v3.3.0a1~1809^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c;p=python 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. --- f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c diff --cc Lib/test/regrtest.py index 9bb43078e3,077434baaf..ef8ea6d918 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@@ -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) @@@ -606,7 -554,7 +609,8 @@@ (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() @@@ -692,7 -633,7 +696,8 @@@ 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 @@@ -861,10 -802,8 +867,11 @@@ 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: diff --cc Lib/test/support.py index 8a60ba995e,e82a4f9316..64c1b4e454 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@@ -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 0b205ad9a8,ef432e0d29..5ab2d17ed6 --- a/Misc/NEWS +++ 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.