Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Phantom-Wan video generation project. It transitions the project from simple pip-based dependency management to Poetry, and sets up a complete pytest-based testing framework ready for developers to write tests.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with all dependencies from requirements.txt
  • Python Version: Set to Python 3.10+ (required by Gradio)
  • Optional Dependencies: Made flash-attn optional for CPU environments via Poetry extras

Testing Framework

  • Testing Dependencies: Added as development dependencies:
    • pytest (^8.0.0) - Core testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities
    • pytest-xdist (^3.6.0) - Parallel test execution
    • pytest-timeout (^2.3.0) - Test timeout management

Testing Configuration

  • pytest Configuration in pyproject.toml:

    • Test discovery patterns for various naming conventions
    • Custom markers: unit, integration, slow, gpu, network
    • Strict mode enabled for better error detection
    • Coverage configuration with 80% threshold (configurable)
  • Coverage Settings:

    • Source: phantom_wan package
    • Output formats: Terminal, HTML, XML
    • Exclusions for test files, __init__.py, virtual environments

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 management
  • mock_config: Configuration dictionary for testing
  • sample_image: Creates test images
  • sample_video_frames: Creates test video frame sequences
  • mock_torch_tensor, mock_numpy_array: Test data
  • mock_model, mock_pipeline: Model/pipeline mocks
  • env_vars: Environment variable management
  • capture_logs: Log capture for testing
  • gpu_available: GPU availability check
  • And more...

Development Tools

  • Added linting/formatting tools: black, isort, flake8, mypy
  • Added pre-commit for git hooks
  • Poetry scripts: poetry run test and poetry run tests

Updated .gitignore

  • Added testing artifacts: .pytest_cache/, .coverage, htmlcov/, etc.
  • Added Claude settings: .claude/
  • Added development tools and IDE files
  • Preserved existing project-specific ignores

How to Use

Installation

# Install Poetry if not already installed
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

# Install with CUDA support (optional)
poetry install -E cuda

Running Tests

# Run all tests
poetry run test

# Run with coverage
poetry run pytest --cov=phantom_wan

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Run tests in parallel
poetry run pytest -n auto

Writing Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use fixtures from conftest.py for common test needs
  3. Mark tests appropriately: @pytest.mark.unit, @pytest.mark.slow, etc.
  4. Follow naming convention: test_*.py for test files

Notes

  • The project requires Python 3.10+ due to Gradio dependency
  • flash-attn is optional and only installs with CUDA support
  • Coverage is currently disabled in pytest.ini_options to avoid issues with the CUDA-dependent codebase
  • The validation tests pass successfully, confirming the infrastructure is working

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests for individual components
  2. Create integration tests for pipelines
  3. Add performance benchmarks
  4. Set up CI/CD with the test suite
  5. Enable coverage reporting once the codebase is more test-friendly

- Add Poetry for dependency management with pyproject.toml
- Configure pytest with coverage, markers, and custom settings
- Add testing dependencies (pytest, pytest-cov, pytest-mock, etc.)
- Create tests directory structure with unit/integration folders
- Add comprehensive conftest.py with reusable fixtures
- Create validation tests to verify infrastructure setup
- Update .gitignore with testing and Claude-related entries
- Make flash-attn optional for CPU environments
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