def filter_testsuite(suite, matcher, level=None):
 if (not isinstance(suite, unittest.TestSuite)):
  raise TypeError('not a TestSuite', suite)
 results = []
 for test in suite._tests:
  if ((level is not None) and (getattr(test, 'level', 0) > level)):
   continue
  if isinstance(test, unittest.TestCase):
   testname = test.id()
   if matcher(testname):
    results.append(test)
  else:
   filtered = filter_testsuite(test, matcher, level)
   results.extend(filtered)
 return results

def filter_testsuite ( suite , matcher , level = None ) : if ( not isinstance ( suite , unittest . TestSuite ) ) : raise TypeError ( 'not a TestSuite' , suite ) results = [ ] for test in suite . _tests : if ( ( level is not None ) and ( getattr ( test , 'level' , 0 ) > level ) ) : continue if isinstance ( test , unittest . TestCase ) : testname = test . id ( ) if matcher ( testname ) : results . append ( test ) else : filtered = filter_testsuite ( test , matcher , level ) results . extend ( filtered ) return results
returns a flattened list of test cases that match the given matcher .