MixNMatch
MixNMatch 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 Python project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with proper coverage reporting and organization.
Changes Made
Package Management
- Poetry Configuration: Set up Poetry as the package manager with a complete
pyproject.tomlconfiguration - No Migration Needed: No existing dependencies found in requirements.txt or setup.py
Testing Framework
- Dependencies Added:
pytest(^7.4.0) - Core testing frameworkpytest-cov(^4.1.0) - Coverage reporting pluginpytest-mock(^3.11.0) - Mocking utilities
Configuration
-
pytest Settings:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting in HTML, XML, and terminal formats
- Custom markers:
unit,integration, andslow - Strict marker enforcement
- Verbose output by default
- Test discovery patterns for
-
Coverage Settings:
- Source directory:
code/ - Excluded: tests, cache, virtual environments, migrations
- 80% coverage threshold (informational only)
- HTML reports in
htmlcov/directory - XML reports as
coverage.xml
- Source directory:
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── unit/ # Unit tests directory
│ └── __init__.py
├── integration/ # Integration tests directory
│ └── __init__.py
└── test_setup_validation.py # Validation tests
Fixtures (conftest.py)
temp_dir: Temporary directory with automatic cleanupmock_config: Mock configuration objectsample_data: Sample data for testingmock_model: Mock ML model with predict/train/evaluate methodstest_image_path: Creates temporary test image filesjson_file: Helper for creating temporary JSON filescapture_logs: Log message capture utilityreset_environment: Auto-reset environment variablesmock_file_operations: Mock file system operations
.gitignore Updates
- Python artifacts:
__pycache__/,*.pyc, virtual environments - Testing artifacts:
.pytest_cache/,.coverage,htmlcov/,coverage.xml - Claude artifacts:
.claude/* - IDE and OS files
Running Tests
Basic Commands
# Install dependencies
poetry install
# Run all tests
poetry run test
# or
poetry run tests
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run specific test file
poetry run pytest tests/test_setup_validation.py
# Run with coverage only
poetry run pytest --cov=code --cov-report=html
Validation Results
All 10 validation tests pass successfully:
- ✅ pytest installation verified
- ✅ Project structure validated
- ✅ pyproject.toml configuration checked
- ✅ Custom markers functional
- ✅ Fixtures available and working
- ✅ Coverage tools configured
- ✅ Mock utilities available
- ✅ Code package importable
- ✅ Integration test setup verified
- ✅ Slow marker functional
Notes
- The coverage warning about "no data collected" is expected since we haven't written actual tests for the codebase yet
- Both
poetry run testandpoetry run testscommands are configured and working - The poetry.lock file is NOT gitignored as per best practices
- The 80% coverage threshold is set in the configuration but won't fail builds (removed
--cov-fail-underfrom pytest args)
Next Steps
Developers can now immediately start writing tests by:
- Creating test files in
tests/unit/ortests/integration/ - Using the provided fixtures from
conftest.py - Running tests with
poetry run test - Viewing coverage reports in
htmlcov/index.html