def make_test_case(test_name): """Method test case factory. May return a method test case, or a generator method test suite, if the test case is a generator. """ attr = getattr(cls, test_name) if is_generator(attr): return GeneratorMethodTestSuite(cls, test_name) else: return MethodTestCase(cls, test_name)
def testsInModule(self, module, importPath=None): """Find functions and classes matching testMatch, as well as classes that descend from unittest.TestCase, return all found (properly wrapped) as tests. """ def cmp_line(a, b): """Compare functions by their line numbers """ try: a_ln = func_lineno(a) b_ln = func_lineno(b) except AttributeError: return 0 return cmp(a_ln, b_ln) entries = dir(module) tests = [] func_tests = [] for item in entries: log.debug("module candidate %s", item) test = getattr(module, item) if isinstance(test, (type, types.ClassType)): log.debug("candidate %s is a class", test) if self.selector.wantClass(test): tests.append(TestClass(self.loadTestsFromTestCase, self.conf, test)) elif isfunction(test): log.debug("candidate %s is a function", test) if not self.selector.wantFunction(test): continue # might be a generator # FIXME LazySuite w/ generate...? if is_generator(test): log.debug("test %s is a generator", test) func_tests.extend(self.generateTests(test)) else: # nope, simple functional test func_tests.append(test) # run functional tests in the order in which they are defined func_tests.sort(cmp_line) tests.extend([ FunctionTestCase(test, fromDirectory=importPath) for test in func_tests ]) log.debug("Loaded tests %s from module %s", tests, module.__name__) return tests