USRNet icon indicating copy to clipboard operation
USRNet copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 5 months ago • 0 comments

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.toml with 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.toml with:
    • 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 directory
  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • sample_image_array: NumPy array for image testing
  • sample_tensor: PyTorch tensor for model testing
  • sample_kernel: Blur kernel for image processing tests
  • mock_model_weights: Mock .pth file for model loading tests
  • device: PyTorch device selection (CPU/CUDA)
  • reset_random_seeds: Automatic seed reset for reproducibility
  • capture_logs: Log message capture during tests

Additional Setup

  • Test Scripts: Created executable test and tests scripts 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/ and utils/ 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:

  1. Creating test files in tests/unit/ or tests/integration/
  2. Using the provided fixtures from conftest.py
  3. Following the established patterns from the validation tests

llbbl avatar Jun 28 '25 00:06 llbbl