Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

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

- Configure Poetry package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with shared fixtures
- Add test commands accessible via `poetry run test[s]`
- Update .gitignore with testing and Claude-related entries
- Add validation tests to verify setup functionality
@google-cla
Copy link

google-cla bot commented Jun 15, 2025

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.

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