lightweight_mmm
lightweight_mmm 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 lightweight_mmm project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith complete project configuration - Dependency migration: Transferred all dependencies from
requirements.txtandsetup.pyto Poetry - Development dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
- pytest configuration:
- Set up test discovery patterns
- Configured coverage reporting with 80% threshold
- Added custom markers:
unit,integration, andslow - Configured output formatting and strict options
- Coverage settings:
- HTML and XML report generation
- Exclusion patterns for non-production code
- Branch coverage enabled
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Temporary directory for test filesmock_data: Synthetic MMM data for testingmock_config: Configuration dictionarysample_media_data: Sample media spend datasample_target_data: Sample sales datamock_model_params: Model parameters for testingreset_random_seed: Ensures reproducible testscapture_logs: Log capturing fixture
Development Commands
poetry run test- Run all testspoetry run tests- Alternative command (both work)- All standard pytest options are available
Running Tests
-
Install dependencies:
poetry install -
Run all tests:
poetry run test -
Run with specific markers:
poetry run pytest -m unit # Unit tests only poetry run pytest -m "not slow" # Skip slow tests -
Run with coverage report:
poetry run pytest --cov-report=html
Notes
- The infrastructure is ready for developers to start writing tests immediately
- Coverage threshold is set to 80% to encourage comprehensive testing
- The validation test file (
test_setup_validation.py) verifies the infrastructure works correctly - Poetry lock file is NOT gitignored to ensure reproducible builds
- The existing test files in the lightweight_mmm package remain unchanged