Skip to content

feat: Set up comprehensive testing infrastructure - #22

Open
llbbl wants to merge 1 commit into
lidq92:masterfrom
UnitSeeker:add-testing-infrastructure
Open

llbbl wants to merge 1 commit into
lidq92:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 2, 2025

Copy link
Copy Markdown

Set up comprehensive testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the PyTorch Image Quality Assessment project using modern Python tooling and best practices.

Changes Made

Package Management

  • Added Poetry configuration in pyproject.toml with proper dependency management
  • Migrated from requirements.txt to Poetry for better dependency resolution and virtual environment handling
  • Updated Python version requirement to ^3.9 for compatibility with modern packages

Testing Framework

  • Configured pytest with comprehensive settings including:
    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, slow for test categorization
    • Strict configuration options for robust testing
  • Added pytest-cov for coverage reporting with multiple output formats
  • Added pytest-mock for enhanced mocking capabilities

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test utilities
├── unit/                    # Unit tests
│   └── __init__.py
├── integration/             # Integration tests
│   └── __init__.py
└── test_setup_validation.py # Infrastructure validation tests

Shared Testing Utilities

Created comprehensive fixtures in conftest.py:

  • File system fixtures: temp_dir, sample_image_path
  • Data fixtures: sample_image, sample_tensor, sample_patches, sample_labels
  • Mock objects: mock_config, mock_dataset, mock_dataloader, mock_h5py_file, mock_yaml_config
  • Environment setup: set_random_seeds for reproducible testing, mock_cuda for CI/CD

Coverage Configuration

  • HTML reports generated in htmlcov/ directory
  • XML reports for CI/CD integration (coverage.xml)
  • Terminal output with missing line indicators
  • Exclusion rules for common non-testable code patterns
  • Configurable thresholds for coverage requirements

Development Workflow

  • Poetry scripts: poetry run test and poetry run tests commands
  • Marker-based testing: Run specific test categories with -m unit, -m integration, -m slow
  • Coverage integration: Automatic coverage reporting with all test runs

Infrastructure Improvements

  • Updated .gitignore with comprehensive rules for:
    • Python artifacts (__pycache__/, *.pyc, etc.)
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/)
    • Virtual environments and IDE files
    • Machine learning specific files (.h5, models/, logs/)
    • Claude Code configuration (.claude/)

Running Tests

Basic Usage

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run tests without coverage
poetry run pytest --no-cov

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

Coverage Reports

# Generate HTML coverage report
poetry run pytest --cov-report=html

# View coverage in terminal
poetry run pytest --cov-report=term-missing

Validation

The setup includes validation tests (tests/test_setup_validation.py) that verify:

  • ✅ pytest is working correctly
  • ✅ All fixtures are available and functional
  • ✅ PyTorch and NumPy are properly installed
  • ✅ File creation and mocking utilities work
  • ✅ Coverage reporting is functional
  • ✅ Test markers are properly configured

All validation tests pass, confirming the infrastructure is ready for development.

Dependencies Updated

Updated from legacy versions in requirements.txt to modern, compatible versions:

  • Python: ^3.9 (increased from ^3.8 for scipy compatibility)
  • Core dependencies: h5py, PyYAML, Pillow, numpy, scipy, torch
  • Testing dependencies: pytest ^7.4.0, pytest-cov ^4.1.0, pytest-mock ^3.11.1

Notes

  • The poetry.lock file ensures reproducible installations across environments
  • The testing infrastructure is framework-agnostic and ready for immediate use
  • Coverage thresholds can be adjusted in pyproject.toml as needed
  • Additional fixtures can be easily added to conftest.py for project-specific needs

🤖 Generated with Claude Code

- Add Poetry package manager with pyproject.toml configuration
- Migrate dependencies from requirements.txt to modern package management
- Set up pytest with coverage reporting and custom markers (unit/integration/slow)
- Create testing directory structure with unit and integration test folders
- Add comprehensive shared fixtures in conftest.py for common testing scenarios
- Configure coverage reporting with HTML, XML, and terminal output
- Update .gitignore with Python, testing, ML, and IDE-related entries
- Add validation tests to verify testing infrastructure works correctly
- Enable Poetry script commands for running tests (poetry run test/tests)

Testing infrastructure ready for immediate development use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant