Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 24, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the hymm video generation project, migrating from basic pip requirements to Poetry for modern dependency management and setting up pytest with full coverage reporting.

Changes Made

Package Management Migration

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry
  • Updated numpy version to resolve dependency conflicts
  • Set Python requirement to ^3.9 (required by accelerate)

Testing Framework Setup

  • Added pytest as the testing framework with:
    • pytest-cov for coverage reporting
    • pytest-mock for mocking utilities
  • Configured comprehensive pytest settings:
    • Test discovery patterns for multiple naming conventions
    • Coverage reporting with 80% threshold (adjustable)
    • HTML and XML coverage report generation
    • Custom test markers: unit, integration, slow
    • Strict configuration and error handling

Test Directory Structure

tests/
├── __init__.py
├── conftest.py           # Shared fixtures and configuration
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/
│   ├── __init__.py
│   └── test_example.py   # Example unit tests
└── integration/
    └── __init__.py

Shared Test Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Configuration dictionary for testing
  • sample_image_array: 224x224x3 RGB test image
  • sample_video_frames: 10 frames of 128x128x3 video
  • sample_audio_array: 1-second audio signal at 16kHz
  • Mock fixtures for models, pipelines, encoders, and VAE
  • test_data_dir: Test directory with sample files
  • env_vars: Environment variable management
  • capture_logs: Log message assertion helper
  • test_helpers: Utility methods for array assertions

Development Experience

  • Poetry scripts configured: poetry run test or poetry run tests
  • All standard pytest options available
  • Comprehensive .gitignore updates for Python development
  • CLAUDE.md updated with testing commands

Running Tests

  1. Install dependencies:

    poetry install
  2. Run all tests with coverage:

    poetry run test
    # or
    poetry run tests
  3. Run tests without coverage:

    poetry run pytest --no-cov
  4. Run specific test markers:

    poetry run pytest -m unit
    poetry run pytest -m integration
    poetry run pytest -m "not slow"
  5. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI integration

Notes

  • Python Version: Requires Python 3.9+ due to the accelerate dependency
  • Coverage: Currently set to 0% threshold for validation tests; should be increased to 80% when actual code tests are added
  • No Production Tests: This PR only sets up infrastructure and validation tests. Actual unit tests for the codebase should be added in subsequent PRs
  • Poetry Lock: The poetry.lock file is committed to ensure reproducible builds

Next Steps

  1. Write unit tests for core modules in hymm_sp/
  2. Add integration tests for the Gradio/Flask interfaces
  3. Set up CI/CD pipeline with the coverage reports
  4. Consider adding additional testing tools (e.g., black, flake8, mypy) for code quality

- Migrate from requirements.txt to Poetry for modern dependency management
- Add pytest with coverage reporting and mocking capabilities
- Configure test discovery, coverage thresholds, and custom markers
- Create organized test directory structure with shared fixtures
- Update .gitignore with testing and Poetry-related entries
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