def partition_suite_by_case(suite):
 groups = []
 suite_class = type(suite)
 for (test_type, test_group) in itertools.groupby(suite, type):
  if issubclass(test_type, unittest.TestCase):
   groups.append(suite_class(test_group))
  else:
   for item in test_group:
    groups.extend(partition_suite_by_case(item))
 return groups

def partition_suite_by_case ( suite ) : groups = [ ] suite_class = type ( suite ) for ( test_type , test_group ) in itertools . groupby ( suite , type ) : if issubclass ( test_type , unittest . TestCase ) : groups . append ( suite_class ( test_group ) ) else : for item in test_group : groups . extend ( partition_suite_by_case ( item ) ) return groups
partitions a test suite by test case .