Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the video-depixelation project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Management: Migrated from manual dependency management to Poetry
  • Lock File: Generated poetry.lock for reproducible builds

Testing Framework

  • pytest: Main testing framework with comprehensive configuration
  • pytest-cov: Coverage reporting with HTML and XML output
  • pytest-mock: Mocking utilities for test isolation

Project Structure

tests/
├── __init__.py
├── README.md           # Testing documentation
├── conftest.py         # Shared fixtures and configuration
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/              # Unit tests directory
│   └── __init__.py
└── integration/       # Integration tests directory
    └── __init__.py

Configuration

pytest Configuration (pyproject.toml)

  • Test discovery patterns for flexible naming
  • Coverage reporting with multiple output formats
  • Custom markers: unit, integration, slow, gpu
  • Strict mode for better error detection
  • Coverage threshold initially set to 0% (to be increased as tests are added)

Coverage Settings

  • Source directories: v1/ and v2/
  • Exclusions for test files, caches, and virtual environments
  • HTML report generation in htmlcov/
  • XML report for CI integration

Fixtures (conftest.py)

  • temp_dir: Temporary directory with automatic cleanup
  • mock_config: Configuration dictionary for testing
  • sample_image: PIL Image creation
  • sample_tensor: PyTorch tensor creation
  • mock_frames_folder: Sample video frames setup
  • output_folders: All project output directories
  • device: CPU/CUDA device selection
  • cleanup_cuda: Automatic CUDA cache cleanup

Development Workflow

Running Tests

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with specific options
poetry run pytest -v                    # Verbose
poetry run pytest -m unit              # Only unit tests
poetry run pytest --no-cov             # Without coverage
poetry run pytest -k "test_name"       # Specific test pattern

Coverage Reports

# Terminal coverage report
poetry run pytest --cov-report=term

# HTML coverage report
poetry run pytest --cov-report=html
# Open htmlcov/index.html in browser

Additional Updates

  • .gitignore: Added entries for testing artifacts, coverage reports, Python caches, virtual environments, and IDE files
  • Validation Tests: Created comprehensive tests to verify the infrastructure works correctly

Dependencies Added

Production Dependencies

  • torch ^2.0.0
  • torchvision ^0.15.0
  • pillow ^10.0.0

Development Dependencies

  • pytest ^7.4.0
  • pytest-cov ^4.1.0
  • pytest-mock ^3.11.0

Next Steps

  1. Developers can now start writing unit tests for existing functionality
  2. Coverage threshold should be gradually increased as tests are added
  3. Consider adding pre-commit hooks to run tests automatically
  4. Set up CI/CD to run tests on pull requests

Testing the Setup

The infrastructure has been validated with 18 passing tests that verify:

  • All dependencies are properly installed
  • Fixtures work correctly
  • Test markers are recognized
  • Project structure is valid
  • Coverage reporting functions properly

Run poetry run pytest to see the validation tests in action.

- Set up Poetry package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common test needs
- Update .gitignore with testing and development entries
- Include validation tests to verify infrastructure setup
@KoKuToru KoKuToru force-pushed the master branch 6 times, most recently from fd88538 to e36f5e6 Compare June 17, 2025 07:24
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