Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 20, 2025

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.toml with complete project configuration
  • Dependency migration: Transferred all dependencies from requirements.txt and setup.py to 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, and slow
    • 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 files
  • mock_data: Synthetic MMM data for testing
  • mock_config: Configuration dictionary
  • sample_media_data: Sample media spend data
  • sample_target_data: Sample sales data
  • mock_model_params: Model parameters for testing
  • reset_random_seed: Ensures reproducible tests
  • capture_logs: Log capturing fixture

Development Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)
  • All standard pytest options are available

Running Tests

  1. Install dependencies:

    poetry install
  2. Run all tests:

    poetry run test
  3. Run with specific markers:

    poetry run pytest -m unit  # Unit tests only
    poetry run pytest -m "not slow"  # Skip slow tests
  4. 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

- Migrated from requirements.txt to Poetry for dependency management
- Added pytest, pytest-cov, and pytest-mock as dev dependencies
- Configured pytest with coverage thresholds (80%) and custom markers
- Created test directory structure with unit/integration subdirectories
- Added shared fixtures in conftest.py for common test scenarios
- Updated .gitignore with testing and Claude-specific entries
- Created validation tests to verify infrastructure setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant