Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Video Depth Anything project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and maintaining tests throughout the project.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
  • Optional Dependencies: Marked decord as optional due to platform-specific installation issues

Testing Configuration

  • pytest Configuration: Comprehensive setup in pyproject.toml including:

    • Test discovery patterns for test_*.py and *_test.py
    • Coverage reporting with HTML and XML output
    • Custom markers: unit, integration, slow
    • Strict mode and detailed output formatting
  • Coverage Configuration:

    • Source directories: video_depth_anything, metric_depth, benchmark, utils
    • Exclusions for test files, cache, and virtual environments
    • Coverage threshold set to 0% initially (can be increased as tests are added)

Directory Structure

tests/
├── __init__.py
├── conftest.py
├── test_setup_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing scenarios:

  • temp_dir: Temporary directory management
  • sample_image_path: Test image generation
  • sample_video_path: Mock video file paths
  • sample_tensor: PyTorch tensor fixtures
  • sample_depth_map: Depth map test data
  • mock_model_config & mock_dataset_config: Configuration fixtures
  • torch_deterministic: Ensures reproducible PyTorch operations
  • gpu_available & skip_if_no_gpu: GPU testing utilities

Additional Setup

  • Updated .gitignore: Added entries for:

    • Testing artifacts: .pytest_cache/, .coverage, htmlcov/, coverage.xml
    • Build artifacts and virtual environments
    • Claude settings: .claude/*
    • Note: poetry.lock is gitignored but should be removed from gitignore for production
  • Validation Tests: Created test_setup_validation.py to verify:

    • All testing dependencies are installed correctly
    • Project structure is properly set up
    • Fixtures are working as expected
    • Markers are configured
    • Coverage configuration is in place

Running Tests

After setting up the environment, developers can run tests using:

# Install dependencies
poetry install

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

# Run specific test files
poetry run pytest tests/test_setup_validation.py

# Run tests with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Run tests with coverage only (no fail threshold)
poetry run pytest --cov-fail-under=0

Notes

  1. Coverage Threshold: Currently set to 0% to allow the infrastructure to be set up without requiring immediate test coverage. This should be gradually increased as tests are added.

  2. Decord Package: Marked as optional due to platform-specific installation issues. If needed for testing, it can be installed separately.

  3. Poetry Lock File: Currently gitignored for flexibility during development. For production, remove poetry.lock from .gitignore to ensure reproducible builds.

  4. Next Steps:

    • Start writing unit tests for core modules
    • Add integration tests for end-to-end workflows
    • Gradually increase coverage threshold
    • Set up CI/CD to run tests automatically

Testing the Setup

The validation tests have been run successfully, confirming:

  • ✅ All testing packages are installed
  • ✅ Project structure is correct
  • ✅ Fixtures are working
  • ✅ Test markers are configured
  • ✅ Both poetry run test and poetry run tests commands work

This infrastructure is now ready for developers to start writing comprehensive tests for the Video Depth Anything project.

- Set up Poetry as package manager with all dependencies from requirements.txt
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage reporting (HTML/XML), custom markers, and test discovery
- Create test directory structure with unit/integration subdirectories
- Add comprehensive shared fixtures in conftest.py for common testing scenarios
- Update .gitignore with testing artifacts and build files
- Create validation tests to verify infrastructure setup
- Configure Poetry scripts for running tests with 'poetry run test/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