WLASL icon indicating copy to clipboard operation
WLASL copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the WLASL Python project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Initialized Poetry as the package manager with pyproject.toml
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest ^7.4.0 - Core testing framework
    • pytest-cov ^4.1.0 - Coverage reporting
    • pytest-mock ^3.11.1 - Mocking utilities

Testing Configuration

  • pytest Configuration: Configured in pyproject.toml with:

    • Test discovery patterns for flexible test file naming
    • Coverage settings with 80% threshold requirement
    • HTML and XML coverage report generation
    • Strict markers and configuration
    • Custom markers: unit, integration, slow
  • Coverage Configuration: Set up with:

    • Source directory tracking (code/)
    • Exclusion patterns for test files and virtual environments
    • Branch coverage enabled
    • Multiple report formats

Directory Structure

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

Testing Fixtures

Created comprehensive shared fixtures in conftest.py:

  • temp_dir - Temporary directory with automatic cleanup
  • mock_config - Mock configuration object
  • sample_json_data - Sample JSON test data
  • mock_video_file - Mock video file creation
  • mock_dataset_dir - Complete mock dataset structure
  • mock_model - Mock ML model object
  • mock_data_loader - Mock data loader
  • env_setup - Environment variable setup
  • capture_logs - Log capture during tests
  • cleanup_test_files - Automatic test file cleanup
  • mock_ini_config - Mock INI configuration files

Development Experience

  • Commands: Both poetry run test and poetry run tests work
  • Validation: Created validation tests to verify the infrastructure
  • Git Integration: Updated .gitignore with comprehensive patterns

How to Use

  1. Install dependencies:

    poetry install --with test
    
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
    
  3. Run specific test categories:

    # Unit tests only
    poetry run pytest -m unit
    
    # Integration tests only  
    poetry run pytest -m integration
    
    # Exclude slow tests
    poetry run pytest -m "not slow"
    
  4. Run with coverage:

    poetry run pytest --cov
    
  5. Generate coverage reports:

    • HTML report: htmlcov/index.html
    • XML report: coverage.xml

Notes

  • The infrastructure is ready for immediate test development
  • Coverage threshold is set to 80% but will initially fail since there's no source code to cover
  • All validation tests pass, confirming the setup is working correctly
  • Poetry.lock file is not gitignored to ensure reproducible builds

llbbl avatar Jun 15 '25 00:06 llbbl