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
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
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)
def is_test_module(module: ModuleType) -> bool: return is_test_module_name(module.name)
def is_test_module(module: pkgutil.ModuleInfo) -> bool: return is_test_module_name(module.name)