USRNet
USRNet copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the USRNet project using Poetry for dependency management and pytest as the testing framework. The setup provides a ready-to-use environment for developers to immediately start writing unit and integration tests.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry as the package manager - Dependencies: Migrated project dependencies including PyTorch, OpenCV, NumPy, SciPy, and Matplotlib
- Development Dependencies: Added pytest, pytest-cov, and pytest-mock for testing
Testing Configuration
- pytest Settings: Configured in
pyproject.tomlwith:- Test discovery patterns for flexible test file naming
- Coverage reporting with 80% threshold requirement
- HTML and XML coverage report generation
- Custom markers for unit, integration, and slow tests
- Strict mode and helpful output formatting
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
project_root: Access to project root directorytemp_dir: Temporary directory for test filesmock_config: Mock configuration dictionarysample_image_array: NumPy array for image testingsample_tensor: PyTorch tensor for model testingsample_kernel: Blur kernel for image processing testsmock_model_weights: Mock .pth file for model loading testsdevice: PyTorch device selection (CPU/CUDA)reset_random_seeds: Automatic seed reset for reproducibilitycapture_logs: Log message capture during tests
Additional Setup
- Test Scripts: Created executable
testandtestsscripts for convenient test execution - .gitignore: Updated with comprehensive testing artifacts exclusions and Claude settings
- Validation Tests: Added tests to verify the infrastructure works correctly
Running Tests
After setting up the environment with Poetry, you can run tests using:
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# or use the convenience scripts
./test
./tests
# Run with specific options
poetry run pytest -v # Verbose output
poetry run pytest -k "test_name" # Run specific test
poetry run pytest -m unit # Run only unit tests
poetry run pytest --run-slow # Include slow tests
Notes
- The infrastructure is set up but does not include actual unit tests for the codebase
- OpenCV may require additional system dependencies (
libGL.so.1) on some systems - Coverage is configured to monitor the
models/andutils/directories - The setup uses package-mode = false in Poetry since this is a research project, not a distributable package
Next Steps
Developers can now immediately start writing tests by:
- Creating test files in
tests/unit/ortests/integration/ - Using the provided fixtures from
conftest.py - Following the established patterns from the validation tests