def build_suite(self, loaded_module): """ loads the found tests and builds the test suite """ tag_list = [] attrs = {} loader = unittest.TestLoader() suite = OpenCafeUnittestTestSuite() loaded = LoadedTestClass(loaded_module) if self.tags: tag_list, attrs, token = self._parse_tags(self.tags) if (hasattr(loaded_module, "load_tests") and not self.supress and self.method_regex == "test_*" and self.tags is None): load_tests = getattr(loaded_module, "load_tests") suite.addTests(load_tests(loader, None, None)) return suite for class_ in loaded.get_instances(): for method_name in dir(class_): load_test_flag = False if fnmatch(method_name, self.method_regex): if not self.tags: load_test_flag = True else: load_test_flag = self._check_method( class_, method_name, tag_list, attrs, token) if load_test_flag: suite.addTest(class_(method_name)) return suite
def generate_suite(self): """ creates a single unittest test suite """ master_suite = OpenCafeUnittestTestSuite() modules = self.get_modules() for modname in modules: suite = self.build_suite(modname) if suite: master_suite.addTests(suite) return master_suite
def generate_suite(self): """ creates a single unittest test suite """ master_suite = OpenCafeUnittestTestSuite() modules = self.get_modules() for modname in modules: suite = self.build_suite(modname) if suite: master_suite.addTests(suite) return master_suite
def build_suite(self, module_path): """ loads the found tests and builds the test suite """ tag_list = [] attrs = {} loader = unittest.TestLoader() suite = OpenCafeUnittestTestSuite() try: loaded_module = import_module(module_path) except Exception as e: sys.stderr.write("{0}\n".format("=" * 70)) sys.stderr.write( "Failed to load module '{0}'\n".format(module_path, e)) sys.stderr.write("{0}\n".format("-" * 70)) print_exc(file=sys.stderr) sys.stderr.write("{0}\n".format("-" * 70)) return if self.tags: tag_list, attrs, token = self._parse_tags(self.tags) if (hasattr(loaded_module, "load_tests") and not self.supress and not self.method_regex and self.tags is None): load_tests = getattr(loaded_module, "load_tests") suite.addTests(load_tests(loader, None, None)) return suite for class_ in self.get_classes(loaded_module): for method_name in dir(class_): if (method_name.startswith("test_") and search(self.method_regex, method_name) and (not self.tags or self._check_method( class_, method_name, tag_list, attrs, token))): suite.addTest(class_(method_name)) return suite
def build_suite(self, module_path): """ loads the found tests and builds the test suite """ tag_list = [] attrs = {} loader = unittest.TestLoader() suite = OpenCafeUnittestTestSuite() try: loaded_module = import_module(module_path) except Exception as e: sys.stderr.write("{0}\n".format("=" * 70)) sys.stderr.write("Failed to load module '{0}'\n".format( module_path, e)) sys.stderr.write("{0}\n".format("-" * 70)) print_exc(file=sys.stderr) sys.stderr.write("{0}\n".format("-" * 70)) return if self.tags: tag_list, attrs, token = self._parse_tags(self.tags) if (hasattr(loaded_module, "load_tests") and not self.supress and not self.method_regex and self.tags is None): load_tests = getattr(loaded_module, "load_tests") suite.addTests(load_tests(loader, None, None)) return suite for class_ in self.get_classes(loaded_module): for method_name in dir(class_): if (method_name.startswith("test_") and search(self.method_regex, method_name) and (not self.tags or self._check_method( class_, method_name, tag_list, attrs, token))): suite.addTest(class_(method_name)) return suite