Пример #1
0
def get_tests(app, app_label_parts, discovery_root):
    tests = []
    for file_path in get_py_files(discovery_root):
        with open(file_path) as python_file:
            data = python_file.read()
            class_and_method_names = app_label_parts[1:]
            if all([re.search(r"\b{}\b".format(item), data) for item in class_and_method_names]):
                test_case_path = build_test_case_path(discovery_root, class_and_method_names, file_path)
                new_path = '.'.join(app.__name__.split('.')[:-1]) + '.' + test_case_path
                tests.append(defaultTestLoader.loadTestsFromName(new_path))
                break
    return tests
Пример #2
0
def get_tests(app, app_label_parts, discovery_root):
    tests = []
    for file_path in get_py_files(discovery_root):
        with open(file_path) as python_file:
            data = python_file.read()
            class_and_method_names = app_label_parts[1:]
            if all([re.search(r"\b{}\b".format(item), data) for item in class_and_method_names]):
                test_case_path = build_test_case_path(discovery_root, class_and_method_names, file_path)
                new_path = '.'.join(app.__name__.split('.')[:-1]) + '.' + test_case_path
                tests.append(defaultTestLoader.loadTestsFromName(new_path))
                break
    return tests
Пример #3
0
    def get_tests_one(self, app_label_parts, discovery_root):
        tests = []
        for file_path in self.get_py_files(discovery_root):
            with open(file_path) as python_file:
                data = python_file.read()

                class_and_method_names = app_label_parts[1:]
                if all([True if item in data else False for item in class_and_method_names]):
                    test_case_path = self.build_test_case_path(class_and_method_names, file_path)
                    try:
                        tests.append(defaultTestLoader.loadTestsFromName(test_case_path))
                    except AttributeError:
                        pass #This means a class name was found but wasn't a class
        return tests
Пример #4
0
 def run(self, ns):
     # If asked to, re-execute without locale
     if ns.reexec and sys.platform != 'win32':
         self._reexec_without_locale()
     if isinstance(self.loader, str):
         suite = defaultTestLoader.loadTestsFromName(self.loader)
     else:
         suite = self.loader()
     # Use standard unittest runner, it has somewhat annoying way of
     # displaying test progress but is well-known and will do for now.
     runner = TextTestRunner(verbosity=ns.verbosity, failfast=ns.fail_fast)
     result = runner.run(suite)
     # Forward the successfulness of the test suite as the exit code
     return 0 if result.wasSuccessful() else 1