augmix icon indicating copy to clipboard operation
augmix copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 1 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the AugMix project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with complete Poetry setup
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Updated Dependencies: Updated torch and torchvision to compatible versions (>=1.9.0 and >=0.10.0)

Testing Framework

  • pytest: Main testing framework with comprehensive configuration
  • pytest-cov: Coverage reporting with HTML and XML output
  • pytest-mock: Mocking utilities for unit tests

Project Structure

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

Configuration Details

  • Test Discovery: Configured to find test_*.py and *_test.py files
  • Coverage Settings:
    • Currently set to 0% threshold (TODO: increase to 80% when tests are written)
    • Generates HTML reports in htmlcov/
    • Generates XML reports as coverage.xml
    • Excludes third-party code, tests, and virtual environments from coverage
  • Custom Markers: unit, integration, and slow for test categorization
  • Shared Fixtures in conftest.py:
    • temp_dir: Temporary directory for file operations
    • mock_config: Mock configuration dictionary
    • sample_image_path: Creates dummy image files
    • mock_dataset_config: Mock dataset configuration
    • reset_random_seeds: Ensures reproducible tests
    • capture_output: Captures stdout/stderr

Development Commands

Run tests using either command:

poetry run test
poetry run tests

Both commands will:

  • Execute all tests
  • Generate coverage reports
  • Show detailed output with missed lines

Additional Setup

  • Updated .gitignore: Added entries for testing artifacts, coverage reports, and Claude settings
  • Validation Tests: Created comprehensive tests to verify the infrastructure works correctly

Usage Instructions

  1. Install dependencies:

    poetry install
    
  2. Run tests:

    poetry run test
    
  3. Run specific test markers:

    poetry run pytest -m unit      # Run only unit tests
    poetry run pytest -m integration  # Run only integration tests
    poetry run pytest -m "not slow"   # Skip slow tests
    
  4. View coverage report:

    open htmlcov/index.html  # macOS
    xdg-open htmlcov/index.html  # Linux
    

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be merged without actual tests
  • Once tests are written, update line 40 in pyproject.toml to set --cov-fail-under=80
  • All validation tests pass, confirming the infrastructure is properly configured
  • The Poetry lock file (poetry.lock) should be committed to ensure reproducible builds

llbbl avatar Jun 15 '25 00:06 llbbl

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jun 15 '25 00:06 google-cla[bot]