diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-29 21:57:10 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-29 21:57:10 (GMT) |
commit | f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c (patch) | |
tree | 7286105d8478aab470f3b2e25d103ddd2b4a3a81 /Lib/test/support.py | |
parent | 4f921c2e061507f6d93002c454e063db2acaf7ea (diff) | |
parent | b9c73e8cf0d0bc70c555521974bc78ae2e890473 (diff) | |
download | cpython-f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c.zip cpython-f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c.tar.gz cpython-f83e4acbaec012e01e11d5cc4ea6514cf2a7b34c.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 8a60ba9..64c1b4e 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -21,6 +21,7 @@ import subprocess import imp import time import sysconfig +import fnmatch import logging.handlers try: @@ -180,6 +181,7 @@ 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 +match_tests = None # _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. @@ -1268,6 +1270,18 @@ def refcount_test(test): 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: @@ -1302,6 +1316,14 @@ def run_unittest(*classes): suite.addTest(cls) else: suite.addTest(unittest.makeSuite(cls)) + def case_pred(test): + if match_tests is None: + return True + for name in test.id().split("."): + if fnmatch.fnmatchcase(name, match_tests): + return True + return False + _filter_suite(suite, case_pred) _run_suite(suite) |