Exemplo n.º 1
0
 def __init__(self, tests=()):
     if tests and type(tests[0]).__name__ == 'ModuleImportFailure':
         _, exc, _ = sys.exc_info()
         if isinstance(exc, unittest.SkipTest):
             from unittest.loader import _make_failed_load_tests
             suite = _make_failed_load_tests(
                 tests[0]._testMethodName,
                 exc,
                 type(self),
             )
             tests = tuple(suite)
     unittest.TestSuite.__init__(self, tests)
Exemplo n.º 2
0
    def _find_tests(self, start_dir, pattern, namespace=False):
        # Upstream doesn't look for 'load_tests' in start_dir.

        if isdir(start_dir) and not namespace and isfile(join(start_dir, '__init__.py')):
            name = self._get_name_from_path(start_dir)
            package = self._get_module_from_name(name)
            load_tests = getattr(package, 'load_tests', None)
            tests = self.loadTestsFromModule(package, use_load_tests=False)
            if load_tests is not None:
                try:
                    yield load_tests(self, tests, pattern)
                except Exception as e:
                    yield loader._make_failed_load_tests(package.__name__, e, self.suiteClass)
        else:
            for t in super(TestLoader, self)._find_tests(start_dir, pattern):
                yield t
Exemplo n.º 3
0
    def _find_tests(self, start_dir, pattern, namespace=False):
        # Upstream doesn't look for 'load_tests' in start_dir.

        if isdir(start_dir) and not namespace and isfile(join(start_dir, '__init__.py')):
            name = self._get_name_from_path(start_dir)
            package = self._get_module_from_name(name)
            load_tests = getattr(package, 'load_tests', None)
            tests = self.loadTestsFromModule(package)
            if load_tests is not None:
                try:
                    yield load_tests(self, tests, pattern)
                except Exception as e:
                    yield loader._make_failed_load_tests(package.__name__, e, self.suiteClass)
        else:
            for t in super(TestLoader, self)._find_tests(start_dir, pattern):
                yield t
Exemplo n.º 4
0
    def loadTestsFromModule(self, module, use_load_tests=True):
        """Return a suite of all tests cases contained in the given module"""
        tests = []
        for name in dir(module):
            obj = getattr(module, name)
            if isinstance(obj, type) and issubclass(obj, BaseTest):
                tests.append(self.loadTestsFromTestCase(obj))

        load_tests = getattr(module, 'load_tests', None)
        tests = self.suiteClass(tests)
        if use_load_tests and load_tests is not None:
            try:
                tests = load_tests(self, tests, None)
            except Exception as e:
                tests = _make_failed_load_tests(module.__name__, e,
                                                self.suiteClass)
        return self.filter_and_sort_tests(tests)