Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jul 1, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the PDVC (Parallel Decoding for Video Captioning) project. It introduces Poetry as the package manager, sets up pytest with coverage reporting, and creates a foundation for writing unit and integration tests.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirement.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:
    • Configured test discovery patterns
    • Set up coverage reporting with 80% threshold
    • Added custom test markers: unit, integration, and slow
    • Configured HTML and XML coverage reports
  • Coverage Settings:
    • Included all main source directories
    • Excluded test files and CUDA operation sources from coverage

Directory Structure

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

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • mock_config: Configuration mocking
  • sample_video_features: Test data for video features
  • sample_captions: Test data for captions
  • mock_model: PyTorch model mocking
  • mock_dataloader: DataLoader mocking
  • sample_yaml_config: YAML configuration testing
  • mock_h5_file: HDF5 file mocking
  • device: CUDA/CPU device selection
  • reset_random_seeds: Reproducibility fixture

Additional Updates

  • Updated .gitignore to exclude testing artifacts and poetry.lock
  • Created validation tests to ensure infrastructure works correctly

Running Tests

Using Poetry Commands

# Install dependencies
poetry install

# Run all tests
poetry run test
# or
poetry run tests

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

# Run with coverage report
poetry run pytest --cov-report=html

Direct pytest Usage

# After activating the virtual environment
pytest
pytest -v  # Verbose output
pytest tests/unit/  # Run only unit tests

Notes

  • The coverage threshold is set to 80% but currently the project has 0% coverage as no actual unit tests have been written yet
  • The testing infrastructure is ready for developers to start writing tests immediately
  • All test dependencies are isolated in the development dependency group
  • The validation tests confirm that all components are properly installed and configured

Next Steps

  1. Write unit tests for core modules (pdvc, video_backbone, data)
  2. Add integration tests for the full pipeline
  3. Set up continuous integration to run tests automatically
  4. Consider adding additional testing tools (e.g., hypothesis for property-based testing)

- Set up Poetry as package manager with pyproject.toml configuration
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Configure pytest with coverage reporting, custom markers, and test discovery
- Create tests directory structure with unit/integration subdirectories
- Add comprehensive test fixtures in conftest.py for mocking and testing
- Update .gitignore with testing and claude-related entries
- Include 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