rcg
rcg copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the RCG (Representation-Conditioned image Generation) project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Transferred all dependencies from
setup.pyandenvironment.yaml - Lock File: Generated
poetry.lockto ensure reproducible builds
Testing Framework
- pytest: Main testing framework with comprehensive configuration
- pytest-cov: Coverage reporting with HTML and XML outputs
- pytest-mock: Mocking utilities for unit tests
- pytest-xdist: Parallel test execution support
- pytest-timeout: Test timeout management
Testing Configuration
- Coverage Settings: Configured with detailed exclusions and reporting formats
- Test Markers: Added
unit,integration, andslowmarkers for test categorization - Strict Mode: Enabled strict markers and configuration for better test quality
- Coverage Reports: HTML reports in
htmlcov/and XML incoverage.xml
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Temporary directory for test filesmock_config: Mock configuration using OmegaConfsample_tensor: Sample PyTorch tensorssample_batch: Sample data batchesnumpy_random_state: Reproducible numpy random statetorch_random_state: Reproducible PyTorch random statemock_model_checkpoint: Mock checkpoint filesmock_image_file: Mock image files for testingdevice: Automatic CPU/GPU device selectioncleanup_cuda: Automatic CUDA cache cleanupmock_environment_variables: Temporary environment variable managementcapture_logs: Log capture for assertions
Additional Tools
- black: Code formatting (configured)
- isort: Import sorting (configured)
- flake8: Linting
- mypy: Type checking (configured)
Updated Files
.gitignore: Added testing, coverage, Claude settings, and build artifact entries- Removed old
setup.pyin favor of Poetry
How to Use
Installation
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
Running Tests
# Run all tests
poetry run test
# Alternative command (both work)
poetry run tests
# Run specific test file
poetry run pytest tests/test_file.py
# Run tests with specific markers
poetry run pytest -m unit # Only unit tests
poetry run pytest -m "not slow" # Skip slow tests
poetry run pytest -m integration # Only integration tests
# Run tests in parallel
poetry run pytest -n auto
# Run with verbose output
poetry run pytest -v
Coverage Reports
- Terminal: Coverage summary shown after each test run
- HTML Report: Open
htmlcov/index.htmlin a browser - XML Report:
coverage.xmlfor CI/CD integration
Writing Tests
- Place unit tests in
tests/unit/ - Place integration tests in
tests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately (
@pytest.mark.unit,@pytest.mark.slow, etc.)
Notes
- Coverage threshold is currently disabled in the configuration. Enable it by uncommenting
--cov-fail-under=80inpyproject.tomlonce tests are added - The validation test file (
test_setup_validation.py) verifies the infrastructure is working correctly - All testing dependencies are in the
devgroup and won't be installed in production
Next Steps
- Write unit tests for existing modules
- Add integration tests for key workflows
- Enable coverage threshold once baseline coverage is established
- Consider adding pre-commit hooks for automated testing