Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 29, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the VISTA project, migrating from traditional pip/requirements.txt to Poetry for modern dependency management and setting up pytest with coverage reporting.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with all dependencies from requirements.txt
  • Preserved all dependencies: Maintained exact dependency specifications including version constraints
  • Added development dependencies: pytest, pytest-cov, and pytest-mock

Testing Configuration

  • pytest configuration in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with 80% threshold requirement
    • Multiple output formats: terminal, HTML, and XML reports
    • Custom markers: unit, integration, and slow
    • Strict mode enabled with verbose output
  • Coverage configuration:

    • Source set to vwm package
    • Branch coverage enabled
    • Exclusions for test files, __init__.py, and common patterns
    • HTML reports in htmlcov/ directory
    • XML reports for CI integration

Directory Structure

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

Test Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: OmegaConf configuration for testing
  • sample_tensor: Sample PyTorch tensors
  • sample_video_tensor: Video tensors for temporal models
  • mock_dataset_item: Mock dataset items
  • mock_model_state: Model state dictionaries
  • device: CPU/GPU device selection
  • mock_checkpoint_path: Checkpoint paths
  • reset_random_seeds: Reproducible tests
  • mock_wandb: Mocked Weights & Biases
  • mock_env_vars: Test environment variables
  • capture_stdout: Output capture utility

Additional Setup

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • IDE files (VSCode workspace files)
  • Created validation tests to verify the infrastructure

How to Use

Install Dependencies

poetry install --with dev

Run Tests

Both commands work identically:

poetry run test
# or
poetry run tests

Run with Options

# Run specific tests
poetry run test tests/unit/

# Run with markers
poetry run test -m unit
poetry run test -m "not slow"

# Run without coverage
poetry run test --no-cov

# Run specific test file
poetry run test tests/test_setup_validation.py

Coverage Reports

  • Terminal: Shown by default after test run
  • HTML: Open htmlcov/index.html in browser
  • XML: Available at coverage.xml for CI tools

Notes

  • The infrastructure is ready for developers to start writing tests
  • No actual unit tests for the codebase were created - only infrastructure setup
  • Poetry lock file should be committed to ensure reproducible builds
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • The validation test that imports the main package may fail due to missing optional dependencies (like open_clip), but this doesn't affect the testing infrastructure itself

Next Steps

  1. Developers can now create unit tests in tests/unit/
  2. Integration tests go in tests/integration/
  3. Use the provided fixtures in conftest.py for common test needs
  4. Mark slow tests with @pytest.mark.slow to exclude them during rapid development

- Migrated from requirements.txt to Poetry for modern dependency management
- Added pytest with coverage reporting and custom markers
- Created test directory structure with unit/integration subdirectories
- Configured pytest with 80% coverage threshold and multiple report formats
- Added comprehensive test fixtures in conftest.py
- Set up Poetry script commands for running tests
- Updated .gitignore with testing artifacts and Claude settings
- 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