Exemple #1
0
def load_tests(modules, loader):
    if modules:
        log.info("Executing modules: {0}".format(modules))
        module_suites = []
        for mod_name in modules:
            # Test names like cephfs.test_auto_repair
            module_suites.append(loader.loadTestsFromName(mod_name))
        log.info("Loaded: {0}".format(list(module_suites)))
        return suite.TestSuite(module_suites)
    else:
        log.info("Executing all cephfs tests")
        return loader.discover(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), "cephfs"))
Exemple #2
0
def _create_suite(package_name, test_name, test_dir,
                test_regex=r"(?:^|[b_./-])[Tt]est"):
    loader = GAETestLoader()
    suite = unittest.TestSuite()

    error = None

    def match_fn(test_name):
        """
        Determine whether a qualified test name (module.class.method)
        should be run.
        """

        return not not re.search(test_regex, test_name)

    try:
        if not package_name and not test_name:
                modules = _load_default_test_modules(test_dir)
                for module in modules:
                    suite.addTest(loader.loadTestsFromModule(module, match_fn))
        elif test_name:
                _load_default_test_modules(test_dir)
                suite.addTest(loader.loadTestsFromName(test_name,
                                                       match_fn=match_fn))
        elif package_name:
                package = reload(__import__(package_name))
                module_names = package.__all__
                for module_name in module_names:
                    qualified_name = '%s.%s' % (package_name, module_name)
                    suite.addTest(loader.loadTestsFromName(qualified_name,
                                                           match_fn=match_fn))

        if suite.countTestCases() == 0:
            raise Exception("'%s' is not found or does not contain any matching tests." %  \
                            (test_name or package_name or 'local directory: \"%s\"' % _LOCAL_TEST_DIR))
    except Exception, e:
        error = str(e)
        _log_error(error)
Exemple #3
0
def load_tests(modules, loader):
    if modules:
        log.info("Executing modules: {0}".format(modules))
        module_suites = []
        for mod_name in modules:
            # Test names like cephfs.test_auto_repair
            module_suites.append(loader.loadTestsFromName(mod_name))
        log.info("Loaded: {0}".format(list(module_suites)))
        return suite.TestSuite(module_suites)
    else:
        log.info("Executing all cephfs tests")
        return loader.discover(
            os.path.join(os.path.dirname(os.path.abspath(__file__)), "cephfs")
        )
Exemple #4
0
def load_testsuite(loader, dir):
    """Find tests in 'dir'."""

    suite = unittest.TestSuite()
    files = []
    for f in os.listdir(dir):
        path = join(dir, f)
        if os.path.isfile(path) and fnmatch(f, 'test_*.py'):
            files.append(f)
        elif os.path.isfile(join(path, '__init__.py')):
            suite.addTests(loader.discover(path))
    for f in files:
        # turn 'f' into a filename relative to the toplevel dir...
        f = relpath(join(dir, f), loader._top_level_dir)
        # ...and translate it to a module name.
        f = os.path.splitext(os.path.normpath(f.replace(os.path.sep, '.')))[0]
        suite.addTests(loader.loadTestsFromName(f))
    return suite
Exemple #5
0
def load_testsuite(loader, dir):
    """Find tests in 'dir'."""

    suite = unittest.TestSuite()
    files = []
    for f in os.listdir(dir):
        path = join(dir, f)
        if os.path.isfile(path) and fnmatch(f, 'test_*.py'):
            files.append(f)
        elif os.path.isfile(join(path, '__init__.py')):
            suite.addTests(loader.discover(path))
    for f in files:
        # turn 'f' into a filename relative to the toplevel dir...
        f = relpath(join(dir, f), loader._top_level_dir)
        # ...and translate it to a module name.
        f = os.path.splitext(os.path.normpath(f.replace(os.path.sep, '.')))[0]
        suite.addTests(loader.loadTestsFromName(f))
    return suite