ConsistentID
ConsistentID copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the AI image generation project, migrating from a basic requirements.txt setup to a modern Poetry-based package management system with comprehensive pytest configuration.
Changes Made
Package Management
- Migrated to Poetry: Converted all 211 dependencies from
requirements.txttopyproject.toml - Organized dependencies: Separated development dependencies into a dedicated group
- Fixed version conflicts: Adjusted numpy version constraint to resolve dependency conflicts
Testing Framework Setup
- Added testing dependencies:
pytest- Core testing frameworkpytest-cov- Coverage reportingpytest-mock- Mocking utilities
- Configured pytest in
pyproject.tomlwith:- Test discovery patterns
- Coverage settings (80% threshold)
- Multiple coverage report formats (terminal, HTML, XML)
- Custom markers for test organization
- Strict configuration options
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Configuration
- Coverage configuration:
- Source directories included
- Exclusion patterns for non-application code
- 80% coverage threshold with branch coverage
- HTML reports in
htmlcov/, XML incoverage.xml
- Test markers:
@pytest.mark.unit- Unit tests@pytest.mark.integration- Integration tests@pytest.mark.slow- Slow-running tests
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir- Temporary directory managementtemp_file- Temporary file creationmock_config- Mock configuration dictionarymock_env_vars- Environment variable mockingsample_image_path- Sample image file creationsample_json_data- Sample JSON structuresreset_environment- Auto-cleanup of test environmentmock_model_weights- Mock ML model filescapture_logs- Log capture and assertion
Poetry Commands
Configured Poetry scripts for easy test execution:
poetry run test- Run all testspoetry run tests- Alternative command (both work)- Standard pytest options remain available
Additional Files
.gitignore: Updated with comprehensive Python testing entriesCLAUDE.md: Project memory file with commands and configuration details- Validation tests: Created
test_setup_validation.pyto verify the infrastructure
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install # Install all dependencies # or poetry install --only dev # Install only dev dependencies -
Run tests:
poetry run test # Run all tests poetry run pytest -v # Run with verbose output poetry run pytest -m unit # Run only unit tests -
View coverage reports:
- Terminal: Automatically shown after test run
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The numpy dependency was adjusted to
>=1.24.3,<2.0to resolve version conflicts with other packages - Poetry lock file is intentionally not gitignored to ensure reproducible builds
- The infrastructure is ready for immediate test development - no actual application tests were written as per requirements
- All validation tests pass, confirming the infrastructure is properly configured
Next Steps
Developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures from
conftest.py - Run tests with coverage reporting
- Use markers to organize and selectively run tests