def decorator_test(func): unwrapped = inspect.unwrap(func) module_name: str = unwrapped.__module__ is_home_module: bool = "." not in module_name if is_test_module_name(module_name) and is_home_module: force_path: Path = kwargs.get("_force_path") if force_path: path = force_path.absolute() else: path = get_absolute_path(unwrapped) if hasattr(unwrapped, "ward_meta"): unwrapped.ward_meta.description = description unwrapped.ward_meta.tags = tags unwrapped.ward_meta.path = path else: unwrapped.ward_meta = WardMeta( description=description, tags=tags, path=path, ) collect_into = kwargs.get("_collect_into", anonymous_tests) collect_into[path].append(unwrapped) @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper return func
def get_tests_in_modules( modules: Iterable, capture_output: bool = True) -> Generator[Test, None, None]: for mod in modules: mod_name = mod.__name__ mod_path = get_absolute_path(mod) anon_tests: List[Callable] = anonymous_tests[mod_path] if anon_tests: for test_fn in anon_tests: meta: WardMeta = getattr(test_fn, "ward_meta") yield Test( fn=test_fn, module_name=mod_name, marker=meta.marker, description=meta.description or "", capture_output=capture_output, )