Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(854)

Unified Diff: Lib/test/support.py

Issue 12231: regrtest: add -k and -K options to filter tests by function/file names
Patch Set: Created 1 year, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/regrtest.py ('k') | Lib/unittest/loader.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -1270,19 +1270,28 @@ def _run_suite(suite):
def run_unittest(*classes):
"""Run tests from unittest.TestCase-derived classes."""
+ regexes = run_unittest.regexes
+ if regexes:
+ def filter_test(name):
+ return any(regex.search(name) for regex in regexes)
+ else:
+ filter_test = None
valid_types = (unittest.TestSuite, unittest.TestCase)
suite = unittest.TestSuite()
for cls in classes:
if isinstance(cls, str):
if cls in sys.modules:
- suite.addTest(unittest.findTestCases(sys.modules[cls]))
+ suite.addTest(unittest.findTestCases(sys.modules[cls], filter=filter_test))
else:
raise ValueError("str arguments must be keys in sys.modules")
elif isinstance(cls, valid_types):
suite.addTest(cls)
else:
- suite.addTest(unittest.makeSuite(cls))
+ suite.addTest(unittest.makeSuite(cls, filter=filter_test))
_run_suite(suite)
+# List of regex objects used to filter the tests by their function name.
+# An empty list means that all tests are used.
+run_unittest.regexes = []
#=======================================================================
« no previous file with comments | « Lib/test/regrtest.py ('k') | Lib/unittest/loader.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7