Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 4, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Deep Supervision project, providing a ready-to-use testing environment with modern Python tooling and best practices.

Changes Made

Package Management

  • Poetry Setup: Added pyproject.toml with Poetry configuration as the primary package manager
  • Dependencies: Configured core dependencies (PyTorch, torchvision, numpy, Pillow) and testing dependencies
  • Dependency Groups: Organized testing dependencies in a separate [tool.poetry.group.test.dependencies] section

Testing Framework Configuration

  • pytest Configuration: Comprehensive pytest settings in pyproject.toml including:
    • Test discovery patterns (test_*.py, *_test.py)
    • Custom markers: unit, integration, slow
    • Strict configuration options for robust testing
    • Verbose output formatting

Coverage Reporting

  • Coverage Settings: 80% coverage threshold with multiple report formats
  • HTML Reports: Generated in htmlcov/ directory for detailed coverage visualization
  • XML Reports: coverage.xml for CI/CD integration
  • Source Configuration: Covers cifar/ and fine-grained/ modules
  • Exclusions: Properly excludes test files, migrations, and environment directories

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test configuration  
├── test_infrastructure.py   # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Test Fixtures (conftest.py)

Comprehensive fixtures tailored for machine learning and computer vision testing:

  • File System: temp_dir, temp_file, sample_image_paths
  • PyTorch Tensors: sample_tensor, sample_labels, small_image_batch
  • Dataset Fixtures: cifar_like_batch, imagenet_like_batch
  • Configuration Mocks: mock_dataset_config, mock_model_config, mock_training_config
  • Deterministic Testing: Automatic seed setting for reproducible tests
  • Training Utilities: mock_checkpoint_data, mock_loss_history

Development Environment

  • .gitignore: Comprehensive exclusions for Python, PyTorch, testing artifacts, and development tools
  • Deterministic Testing: Configured automatic seeding for PyTorch and NumPy
  • IDE Support: Excluded common IDE files and directories

Testing Commands

After this setup, developers can immediately start testing with:

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test types  
poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only  
poetry run pytest -m slow        # Slow tests only

# Run without coverage (for faster iteration)
poetry run pytest --no-cov

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

Validation

  • ✅ All dependencies install successfully
  • ✅ pytest discovers and runs tests correctly
  • ✅ Coverage reporting generates HTML and XML reports
  • ✅ Custom markers work for test filtering
  • ✅ All shared fixtures are functional
  • ✅ Deterministic testing environment verified
  • ✅ Testing directory structure follows best practices

Infrastructure Features

Ready for ML/CV Development

  • PyTorch and torchvision fixtures for tensor operations
  • CIFAR-10 and ImageNet-like batch fixtures
  • Deterministic behavior for reproducible tests
  • GPU/CPU device handling fixtures

Extensible Architecture

  • Modular fixture design in conftest.py
  • Separate unit and integration test directories
  • Configurable coverage thresholds and reporting
  • Custom markers for test categorization

Developer Experience

  • Clear separation of test types
  • Comprehensive test examples in validation suite
  • Mock utilities with pytest-mock integration
  • Temporary file/directory management

Notes

  • Coverage Threshold: Set to 80% - adjust in pyproject.toml if needed
  • Lock File: poetry.lock is tracked for reproducible dependency resolution
  • Python Version: Configured for Python ^3.8 compatibility
  • Framework Agnostic: Infrastructure supports any Python testing approach

The testing infrastructure is now ready for immediate use. Developers can start writing unit and integration tests using the provided fixtures and configuration.

🤖 Generated with Claude Code

- Add Poetry package manager configuration with pyproject.toml
- Configure pytest with coverage reporting (80% threshold)
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create structured test directory with unit/integration subdirectories
- Implement comprehensive conftest.py with shared fixtures for ML/CV testing
- Add custom pytest markers (unit, integration, slow)
- Configure coverage with HTML and XML reporting
- Set up deterministic testing environment with seed control
- Create .gitignore with testing and development exclusions
- Add validation tests to verify infrastructure functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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