✅ all_doctests#
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.
# Create a package whose docstring holds two tests, the second one wrong
mkdir my_package
cat > my_package/geometry.py <<'EOF'
def area(width: float, height: float) -> float:
''' Area of a rectangle.
>>> area(2, 3)
6
>>> area(2.5, 2)
5
'''
return width * height
EOF
# Run every doctest of the package
stouputils all_doctests my_package
launch#
- launch_tests(
- root_dir: str,
- strict: bool = True,
- pattern: str = '*',
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_dirholds no module.
- filter_modules(
- module_paths: list[str],
- pattern: str,
- root_dir: str,
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.
reexports#
Consistency check for packages that re-export their submodules explicitly.
Explicit re-exports are what makes PEP 810 lazy imports possible, since a star import resolves every deferred name at once. The cost is that a new public function is easy to forget in the parent package, so this module compares each submodule against the package that re-exports it.
- module_public_names(module: ModuleType) list[str][source]#
List the public names a module defines itself, ignoring anything it merely imported.
Only objects carrying a __module__ are considered, so plain constants are out of scope.
- Parameters:
module – Module to inspect
- Returns:
Names defined by that module, sorted
>>> from stouputils.all_doctests import reexports >>> module_public_names(reexports) ['find_missing_reexports', 'module_public_names']
- find_missing_reexports(
- package: ModuleType,
Find names a submodule defines that its parent package does not expose at all.
A submodule the parent exposes nothing from counts as deliberately internal and is skipped, which is how modules such as
stouputils.configstay out of the flat namespace. A name the parent already binds to a sibling’s definition is a plain naming clash, not a missing re-export, so it is not reported here either. Submodules that cannot be imported are skipped, since optional dependencies may be absent.- Parameters:
package – Root package to walk
- Returns:
Missing names, keyed by the submodule that defines them
>>> import stouputils >>> find_missing_reexports(stouputils) {}
utils#
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.