def gather_tests(): """Returns unittest.TestSuite instance""" tests = unittest.TestSuite() # unittest for dirpath, dirnames, filenames in os.walk(dirname(__file__)): if 'files' in dirnames: dirnames.remove('files') for name in filenames: if not (name.startswith("test_") and name.endswith(".py")): continue filepath = join(dirpath, name) modulename = resolve_modulename(filepath) module = import_module(modulename) suite = unittest.defaultTestLoader.loadTestsFromModule(module) tests.addTest(suite) # doctest modipyd_dir = join(dirname(__file__), '..', 'modipyd') for modcode in collect_module_code(modipyd_dir): module = import_module(modcode.name) try: suite = doctest.DocTestSuite(module) except ValueError: pass else: tests.addTest(suite) return tests
def collect_unittest(paths): suite = unittest.TestSuite() loader = unittest.defaultTestLoader resolver = resolve.ModuleNameResolver() paths = utils.sequence(paths) for filepath in paths: try: name, package = resolver.resolve(filepath) except ImportError: # .py file not in the search path name = filepath_to_identifier(filepath) package = None try: if package: module = utils.import_module(name) else: module = imp.load_source(name, filepath) except ImportError: LOGGER.warn("ImportError occurred while loading module", exc_info=True) else: tests = loader.loadTestsFromModule(module) if tests.countTestCases(): suite.addTest(tests) LOGGER.info("Found %d test(s) in module '%s'" % (tests.countTestCases(), module.__name__)) else: LOGGER.warn("No tests found in module '%s'" % module.__name__) return suite