This document describes the testing infrastructure and best practices for NumPyMasterPro.
NumPyMasterPro includes a comprehensive test suite covering all utility modules with unit tests, integration tests, and CI/CD automation.
- β
Array Utilities -
test_array_utils.py - β
Logical Utilities -
test_logical_utils.py - β
K-Means Utilities -
test_kmeans_utils.py - β
Math Utilities -
test_math_utils.py - π Additional modules can be tested similarly
Install development dependencies:
pip install -r requirements_dev.txtOr use the Makefile:
make install-devRun all tests:
pytestRun tests with coverage:
pytest --cov=scripts --cov-report=term-missingRun specific test file:
pytest tests/test_logical_utils.py -vRun tests matching a pattern:
pytest -k "test_any_condition" -vWe provide convenient Makefile commands for common tasks:
make test # Run all tests
make test-coverage # Run tests with HTML coverage report
make test-verbose # Run tests with detailed output
make lint # Check code quality
make format # Auto-format code with black & isort
make clean # Remove cache and build artifacts
make all # Run complete check (clean, install, test, lint)tests/
βββ __init__.py # Test package initialization
βββ conftest.py # Shared fixtures and configuration
βββ test_array_utils.py # Tests for array utilities
βββ test_logical_utils.py # Tests for logical operations
βββ test_kmeans_utils.py # Tests for K-Means algorithm
βββ test_math_utils.py # Tests for math operations
Each test file follows this structure:
class TestFeatureName:
"""Group related tests together"""
def test_basic_case(self):
"""Test description"""
# Arrange
arr = np.array([1, 2, 3])
# Act
result = function_under_test(arr)
# Assert
assert result == expected_valueCommon test fixtures are defined in conftest.py:
sample_1d_array- Simple 1D arraysample_2d_array- Simple 2D arrayrandom_array- Random array with fixed seedarray_with_nans- Array containing NaN valuesarray_with_infs- Array with infinite valuesclustering_data- Synthetic clustering dataset
Usage:
def test_with_fixture(sample_1d_array):
result = some_function(sample_1d_array)
assert result.shape == (5,)pytest --cov=scripts --cov-report=term-missingpytest --cov=scripts --cov-report=html
open htmlcov/index.html # View in browserpytest --cov=scripts --cov-report=xmlUse markers to categorize tests:
@pytest.mark.slow
def test_large_dataset():
"""Test with large dataset (takes time)"""
pass
@pytest.mark.unit
def test_single_function():
"""Unit test for isolated function"""
pass
@pytest.mark.integration
def test_workflow():
"""Integration test across modules"""
passRun tests by marker:
pytest -m "not slow" # Skip slow tests
pytest -m "unit" # Run only unit tests
pytest -m "integration" # Run only integration testsTest configuration is defined in pytest.ini:
[pytest]
testpaths = tests
addopts = -v --strict-markers --cov=scriptsTests run automatically via GitHub Actions on:
- β
Push to
mainordevelopbranches - β Pull requests
- β Manual workflow dispatch
- Multi-platform testing (Ubuntu, macOS, Windows)
- Python version matrix (3.10, 3.11, 3.12)
- Code linting (flake8, black, isort)
- Notebook validation
- Docker build verification
- Security scanning (safety, bandit)
- Coverage reporting (Codecov)
touch tests/test_new_module.pyimport pytest
import numpy as np
from scripts.new_module import function_to_testclass TestNewFunction:
def test_basic_behavior(self):
result = function_to_test([1, 2, 3])
assert result == expected
def test_edge_case(self):
with pytest.raises(ValueError):
function_to_test([])pytest tests/test_new_module.py -vβ
Test one thing per test - Keep tests focused
β
Use descriptive names - test_returns_empty_array_for_missing_values
β
Test edge cases - Empty arrays, NaN, inf, negative values
β
Use fixtures - Reuse common test data
β
Check both success and failure - Use pytest.raises() for exceptions
β
Aim for high coverage - Target 80%+ code coverage
β
Keep tests fast - Mark slow tests with @pytest.mark.slow
pytest -vv -spytest --pdbpytest -lpytest --lfΒ© 2025 Satvik Praveen β NumPyMasterPro Testing Guide