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 VideoMamba 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 development tooling.

Changes Made

Package Management Migration

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry
  • Set Python requirement to ^3.9 for compatibility with TensorFlow
  • Made optional dependencies (apex, decord, xformers) that require special installation

Testing Framework Setup

  • Testing Dependencies Added:
    • pytest (^8.1.1) - Main testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities
    • pytest-xdist (^3.6.1) - Parallel test execution
    • pytest-timeout (^2.3.1) - Test timeout management

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py
    • Custom markers: unit, integration, slow, gpu
    • Strict mode with proper error reporting
    • Maximum 3 test failures before stopping
  • Coverage Configuration:

    • Branch coverage enabled
    • HTML and XML report generation
    • Coverage threshold set to 0% (can be increased as tests are added)
    • Proper exclusions for test files and build artifacts

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 with automatic cleanup
  • sample_config / omega_config - Configuration objects
  • mock_video_tensor / mock_image_tensor - Test tensors
  • device - PyTorch device selection
  • mock_checkpoint - Test checkpoint files
  • mock_dataset_root - Mock dataset structure
  • Auto-reset random seeds for reproducibility

Development Tools

  • Linting/Formatting: black, isort, flake8
  • Type Checking: mypy
  • Pre-commit Hooks: pre-commit framework

Updated .gitignore

Added entries for:

  • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
  • Claude settings (.claude/*)
  • Additional IDE and build artifacts
  • Note: poetry.lock is intentionally tracked for reproducibility

How to Use

Install Dependencies

poetry install --with dev

Run Tests

Both commands are available:

poetry run test
# or
poetry run tests

Run with Coverage

poetry run pytest --cov

Run Specific Test Types

poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow"  # Skip slow tests

Run Validation Tests

poetry run pytest tests/test_setup_validation.py -v

Notes

  1. Optional Dependencies: Some dependencies (apex, decord, xformers) require special installation procedures and have been commented out. They can be installed separately as needed.

  2. Coverage Threshold: Currently set to 0% to allow initial setup. This should be gradually increased as more tests are added.

  3. Python Version: Set to Python 3.9+ due to TensorFlow requirements.

  4. Testing Best Practices:

    • Use the provided fixtures in conftest.py
    • Mark tests appropriately (@pytest.mark.unit, etc.)
    • Keep unit tests fast and isolated
    • Use mocking for external dependencies

Next Steps

  1. Start writing unit tests for core modules
  2. Add integration tests for key workflows
  3. Gradually increase coverage threshold
  4. Set up CI/CD pipeline to run tests automatically
  5. Add performance benchmarks using pytest-benchmark if needed

- Migrate from requirements.txt to Poetry package management
- Add pytest, pytest-cov, and pytest-mock for testing
- Configure test discovery, coverage reporting, and custom markers
- Create tests directory structure with shared fixtures in conftest.py
- Add validation tests to verify infrastructure setup
- Update .gitignore with testing artifacts and Claude settings
- Configure Poetry script commands for running tests
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