summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-29 21:53:38 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-29 21:53:38 (GMT)
commitb9c73e8cf0d0bc70c555521974bc78ae2e890473 (patch)
treee90173784f5f835df0755a03ea0321035f3440fb /Lib/test/support.py
parentdef35435ee4001f8aedac01b559bb0dc2d0aab00 (diff)
downloadcpython-b9c73e8cf0d0bc70c555521974bc78ae2e890473.zip
cpython-b9c73e8cf0d0bc70c555521974bc78ae2e890473.tar.gz
cpython-b9c73e8cf0d0bc70c555521974bc78ae2e890473.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.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 09846a8..e82a4f9 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:
@@ -177,6 +178,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.
@@ -1183,6 +1185,18 @@ def check_impl_detail(**guards):
return guards.get(platform.python_implementation().lower(), default)
+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."""
@@ -1218,6 +1232,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)