feat: Set up comprehensive Python testing infrastructure with Poetry
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.tomlwith complete Poetry setup - Dependency Migration: Migrated existing dependencies from
requirements.txtto 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_*.pyand*_test.pyfiles - 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, andslowfor test categorization - Shared Fixtures in
conftest.py:temp_dir: Temporary directory for file operationsmock_config: Mock configuration dictionarysample_image_path: Creates dummy image filesmock_dataset_config: Mock dataset configurationreset_random_seeds: Ensures reproducible testscapture_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
-
Install dependencies:
poetry install -
Run tests:
poetry run test -
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 -
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.tomlto 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
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.