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

Unified Diff: Lib/unittest/loader.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/support.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -45,24 +45,26 @@ class TestLoader(object):
suiteClass = suite.TestSuite
_top_level_dir = None
- def loadTestsFromTestCase(self, testCaseClass):
+ def loadTestsFromTestCase(self, testCaseClass, filter=None):
"""Return a suite of all tests cases contained in testCaseClass"""
if issubclass(testCaseClass, suite.TestSuite):
raise TypeError("Test cases should not be derived from TestSuite." \
" Maybe you meant to derive from TestCase?")
testCaseNames = self.getTestCaseNames(testCaseClass)
+ if filter:
+ testCaseNames = [name for name in testCaseNames if filter(name)]
if not testCaseNames and hasattr(testCaseClass, 'runTest'):
testCaseNames = ['runTest']
loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
return loaded_suite
- def loadTestsFromModule(self, module, use_load_tests=True):
+ def loadTestsFromModule(self, module, use_load_tests=True, filter=None):
"""Return a suite of all tests cases contained in the given module"""
tests = []
for name in dir(module):
obj = getattr(module, name)
if isinstance(obj, type) and issubclass(obj, case.TestCase):
- tests.append(self.loadTestsFromTestCase(obj))
+ tests.append(self.loadTestsFromTestCase(obj, filter=filter))
load_tests = getattr(module, 'load_tests', None)
tests = self.suiteClass(tests)
@@ -311,11 +313,11 @@ def getTestCaseNames(testCaseClass, pref
return _makeLoader(prefix, sortUsing).getTestCaseNames(testCaseClass)
def makeSuite(testCaseClass, prefix='test', sortUsing=util.three_way_cmp,
- suiteClass=suite.TestSuite):
+ suiteClass=suite.TestSuite, filter=None):
return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(
- testCaseClass)
+ testCaseClass, filter=filter)
def findTestCases(module, prefix='test', sortUsing=util.three_way_cmp,
- suiteClass=suite.TestSuite):
- return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(\
- module)
+ suiteClass=suite.TestSuite, filter=None):
+ loader = _makeLoader(prefix, sortUsing, suiteClass)
+ return loader.loadTestsFromModule(module, filter=filter)
« no previous file with comments | « Lib/test/support.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7