Esempio n. 1
0
    def load_custom_test_package(self, module, app_name):
        ''' Load custom test package from module and app '''

        for importer, module_name, ispkg in pkgutil.iter_modules(
                                [os.path.dirname(module.__file__)]):
            try:
                import_module('.'.join([app_name, 'tests']))
            except ImportError, e:
                pass
            else:
                module = import_module('.'.join([app_name, 'tests',
                                             module_name]))
                yield defaultTestLoader.loadTestsFromModule(module)
Esempio n. 2
0
    def build_suite(self, test_labels, extra_tests=None, **kwargs):
        suite = unittest.TestSuite()
        if test_labels:
            for test_label in test_labels:
                # Handle case when app defined with dot
                if '.' in test_label and test_label not in self.get_apps():
                    app_name = test_label.split('.')[0]
                    for app_label in self.get_apps():
                        if test_label.startswith(app_label):
                            app_name = app_label
                    test_module = get_test_module(app_name)

                    parts = test_label[len(app_name) + 1:].split('.')
                    test_module_name = parts[0]
                    new_suite = build_suite(get_app(app_name.split('.')[-1]))
                    if is_custom_test_package(test_module) and not \
                                                        suite.countTestCases():
                        test_module = import_module('.'.join([
                                        app_name, 'tests', test_module_name]))

                        parts_num = len(parts)
                        if parts_num == 1:
                            new_suite = defaultTestLoader.loadTestsFromModule(
                                                                test_module)
                        if parts_num == 2:
                            new_suite = defaultTestLoader.loadTestsFromName(
                                                        parts[1], test_module)
                        elif parts_num == 3:
                            klass = getattr(test_module, parts[1])
                            new_suite = klass(parts[2])

                    suite.addTest(new_suite)
                else:
                    for test_suite in self.load_from_app(test_label):
                        suite.addTest(test_suite)
        else:
            for app in self.get_apps():
                for test_suite in self.load_from_app(app):
                    suite.addTest(test_suite)

        if extra_tests:
            for test in extra_tests:
                suite.addTest(test)

        return reorder_suite(suite, (TestCase,))