stouputils.all_doctests.launch module#

launch_tests(
root_dir: str,
strict: bool = True,
pattern: str = '*',
) → int[source]#

Main function to launch tests for all modules in the given directory.

Parameters:
  • root_dir – Root directory to search for modules

  • strict – Modify the FORCE_RAISE_EXCEPTION configuration to True

  • pattern – Pattern to filter module names (fnmatch style, e.g., ‘typ’, ‘io’, etc.)

Returns:

The number of failed tests

>>> launch_tests("unknown_dir")
Traceback (most recent call last):
        ...
ValueError: No modules found in 'unknown_dir'
> if launch_tests("/path/to/source") > 0:
        sys.exit(1)
[PROGRESS HH:MM:SS] Importing module 'module1'  took 0.001s
[PROGRESS HH:MM:SS] Importing module 'module2'  took 0.002s
[PROGRESS HH:MM:SS] Importing module 'module3'  took 0.003s
[PROGRESS HH:MM:SS] Importing module 'module4'  took 0.004s
[INFO HH:MM:SS] Testing 4 modules...
[PROGRESS HH:MM:SS] Testing module 'module1'    took 0.005s
[PROGRESS HH:MM:SS] Testing module 'module2'    took 0.006s
[PROGRESS HH:MM:SS] Testing module 'module3'    took 0.007s
[PROGRESS HH:MM:SS] Testing module 'module4'    took 0.008s
find_modules(root_dir: str, dir_to_check: str) → list[str][source]#

Dotted names of the modules under root_dir, the shallowest first and then in alphabetical order.

Parameters:

dir_to_check – Folder the names are relative to, the one put on sys.path.

Raises:

ValueError – If root_dir holds no module.

filter_modules(
module_paths: list[str],
pattern: str,
root_dir: str,
) → list[str][source]#

The module names matching an fnmatch pattern, "*" keeping them all.

>>> filter_modules(["pkg.io", "pkg.io.csv", "pkg.typing"], "*io*", "pkg")
['pkg.io', 'pkg.io.csv']
Raises:

ValueError – If no module matches, naming the candidates.

import_modules(
module_paths: list[str],
) → tuple[list[ModuleType], list[str]][source]#

Import each module, timing it, and warn about the ones that fail.

Returns:

The imported modules, and for each one the spaces that align its timing line with the longest name.

report_results(
modules: list[ModuleType],
results: list[TestResults],
) → int[source]#

Print the modules whose tests failed and the totals across all of them.

Returns:

The number of failed tests.