stouputils.all_doctests module#
This module is used to run all the doctests for all the modules in a given directory.
launch_tests: Main function to launch tests for all modules in the given directory.
test_module_with_progress: Test a module with testmod and measure the time taken with progress printing.
- launch_tests(root_dir: str, strict: bool = True) int[source]#
Main function to launch tests for all modules in the given directory.
- Parameters:
root_dir (str) – Root directory to search for modules
strict (bool) – Modify the force_raise_exception variable to True in the decorators module
- Returns:
The number of failed tests
- Return type:
int
Examples
>>> 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
- test_module_with_progress(
- module: ModuleType,
- separator: str,
Test a module with testmod and measure the time taken with progress printing.
- Parameters:
module (ModuleType) – Module to test
separator (str) – Separator string for alignment in output
- Returns:
The results of the tests
- Return type:
TestResults