PyTorch-progressive_growing_of_gans icon indicating copy to clipboard operation
PyTorch-progressive_growing_of_gans copied to clipboard

feat: Set up Python testing infrastructure with Poetry and pytest

Open llbbl opened this issue 5 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the BEGAN PyTorch project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup as the default package manager
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest (^7.4.0) - Main testing framework
    • pytest-cov (^4.1.0) - Coverage reporting
    • pytest-mock (^3.11.0) - Mocking utilities

Testing Configuration

  • pytest Settings: Configured in pyproject.toml with:

    • Test discovery patterns for flexible test file naming
    • Coverage reporting with HTML and XML output formats
    • Custom test markers: unit, integration, slow
    • Strict configuration for better error detection
  • Coverage Settings:

    • Source directories: models/ and utils/
    • Excluded: test files, cache directories, virtual environments
    • Coverage threshold set to 0% (to be increased as tests are added)

Directory Structure

tests/
├── __init__.py
├── conftest.py           # Shared pytest fixtures
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Test Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • sample_data: Mock tensor data for testing
  • mock_model_path: Path utilities for model files
  • reset_modules: Module cleanup between tests
  • capture_stdout: Output capturing for testing print statements
  • test_data_dir: Session-scoped test data directory

Development Workflow

  • Scripts: Added Poetry scripts for running tests
    • poetry run test - Run all tests
    • poetry run tests - Alternative command (both work)

Additional Updates

  • .gitignore: Updated with comprehensive patterns for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Claude settings (.claude/*)
    • Virtual environments and build artifacts
    • IDE files and OS-specific files

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run tests:

    # Run all tests
    poetry run test
    
    # Run with specific options
    poetry run pytest -v
    
    # Run only unit tests
    poetry run pytest -m unit
    
    # Run with coverage report
    poetry run pytest --cov
    
  3. View coverage reports:

    • Terminal: Coverage summary is shown after test runs
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The project's existing code has dependencies on torch and tensorflow which are not included in this testing setup
  • Coverage threshold is currently set to 0% to allow the infrastructure to be established first
  • The validation tests confirm that the testing infrastructure is working correctly
  • Poetry lock file (poetry.lock) is included and should be committed to ensure reproducible builds

Next Steps

  1. Add project dependencies (torch, tensorflow, etc.) to pyproject.toml
  2. Write unit tests for existing modules
  3. Gradually increase coverage threshold as tests are added
  4. Configure CI/CD to run tests automatically

llbbl avatar Jun 29 '25 22:06 llbbl