Ejemplo n.º 1
0
def load_modules(modules: Iterable[pkgutil.ModuleInfo]) -> Generator[Any, None, None]:
    for m in modules:
        if hasattr(m, "module_finder"):
            file_finder: FileFinder = m.module_finder
            spec: ModuleSpec = file_finder.find_spec(m.name)
            m = importlib.util.module_from_spec(spec)
        if is_test_module_name(m.__name__):
            m.__loader__.exec_module(m)
            yield m
Ejemplo n.º 2
0
def load_modules(modules: Iterable[ModuleType]) -> Generator[Any, None, None]:
    for m in modules:
        if hasattr(m, "module_finder"):
            file_finder: FileFinder = m.module_finder
            spec: ModuleSpec = file_finder.find_spec(m.name)
            m = importlib.util.module_from_spec(spec)

        module_name = m.__name__
        if is_test_module_name(module_name):
            if module_name not in sys.modules:
                sys.modules[module_name] = m
            m.__package__ = _build_package_name(m)
            m.__loader__.exec_module(m)
            yield m
Ejemplo n.º 3
0
def testable_test(func):
    """
    Decorate a function with this to treat it as a test that doesn't
    interfere with the "normal" tests, i.e. it collects into a separate
    location, uses a static path, module name etc. Useful for writing
    Ward internal tests.
    """
    func.__module__ = "test_x"
    assert is_test_module_name(func.__module__)
    return test(
        "testable test description",
        _force_path=FORCE_TEST_PATH,
        _collect_into=defaultdict(list),
    )(func)
Ejemplo n.º 4
0
def is_test_module(module: ModuleType) -> bool:
    return is_test_module_name(module.name)
Ejemplo n.º 5
0
def is_test_module(module: pkgutil.ModuleInfo) -> bool:
    return is_test_module_name(module.name)