Testing Module

The tests module provides test discovery and execution utilities for the hiten package.

This module provides functions for automatically discovering and running test files throughout the project using pytest. It includes utilities for finding test files, filtering tests by name patterns, and executing them with appropriate configuration. This module is designed to work with pytest and automatically discovers test files matching the pattern test_*.py throughout the project.

Test Discovery Functions

Functions for discovering and running tests.

hiten.utils.tests.find_test_files()[source]

Find all test_*.py files in the project.

This function recursively searches through the project directory structure to locate all Python files that match the test_*.py pattern. It also ensures that the src directory is added to the Python path so that imports work correctly during test execution.

Returns:

List of absolute file paths to all discovered test files.

Return type:

list of str

Notes

The function automatically adds the src directory to sys.path to ensure proper import resolution during test execution.

Examples

>>> test_files = find_test_files()
>>> len(test_files) > 0
True
>>> all(f.endswith('.py') for f in test_files)
True
hiten.utils.tests.main()[source]

Run the tests using pytest.

This function discovers test files, optionally filters them based on command-line arguments, and executes them using pytest with appropriate configuration options.

Parameters:

sys.argv[1 (] : list of str) – Command-line arguments for filtering tests. If no arguments are provided, all tests are run. If arguments are provided, only tests containing those strings in their file paths are executed.

Return type:

None

Notes

The function uses pytest with the following default options: - -xv: Verbose output with extra information - -s: Don’t capture output (allows print statements to show)

Examples

Run all tests:

python tests.py

Run only polynomial-related tests:

python tests.py polynomials

Run multiple test categories:

python tests.py polynomials linalg