Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the UniRepLKNet project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and maintaining tests across all modules (Audio, Image, Video, Point Cloud, Time-Series, Detection, and Segmentation).

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt files
  • Optional Dependencies: Made platform-specific packages (triton, decord) optional to ensure cross-platform compatibility

Testing Framework

  • pytest Configuration:

    • Configured test discovery patterns
    • Added custom markers: unit, integration, slow
    • Set up coverage reporting (HTML, XML, terminal)
    • Configured strict mode and output formatting
  • Coverage Configuration:

    • Source directories and exclusion patterns defined
    • Multiple report formats configured
    • Coverage thresholds set (currently 0% to allow gradual adoption)

Project Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures for all tests
├── unit/                # Unit tests directory
│   └── __init__.py
├── integration/         # Integration tests directory
│   └── __init__.py
└── test_setup_validation.py  # Validation tests

Shared Fixtures (conftest.py)

Created comprehensive fixtures for testing all module types:

  • General: temp_dir, mock_config, device, random_seed
  • Image/Video: sample_image_tensor, sample_batch, sample_video_tensor
  • Audio: sample_audio_tensor
  • Point Cloud: sample_point_cloud
  • Time Series: sample_time_series
  • Model/Data: mock_model, mock_dataset, mock_dataloader
  • Utilities: checkpoint_path, sample_checkpoint, env_setup, capture_logs

Development Tools

Added development dependencies:

  • Testing: pytest, pytest-cov, pytest-mock
  • Code Quality: black, isort, flake8, mypy
  • Pre-commit: pre-commit hooks configuration

Additional Updates

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

How to Use

Installation

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

Running Tests

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

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

# Run tests with specific marker
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

Writing Tests

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use fixtures from conftest.py for common test needs
  4. Mark tests appropriately: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow

Next Steps

  1. Developers can now start writing unit tests for individual modules
  2. Integration tests can be added for cross-module functionality
  3. Coverage threshold can be gradually increased as more tests are added
  4. Pre-commit hooks can be enabled for automated code quality checks

Notes

  • The Image module was missing __init__.py, which has been added
  • Platform-specific dependencies (triton, decord) are marked as optional
  • Coverage threshold is set to 0% initially to allow immediate use while tests are being written
  • All 23 validation tests pass successfully, confirming the infrastructure is working

- Add pyproject.toml with Poetry configuration and all project dependencies
- Configure pytest with coverage, markers, and comprehensive settings
- Create tests directory structure with unit/integration subdirectories
- Add extensive shared fixtures in conftest.py for all module types
- Create validation tests to verify infrastructure setup
- Update .gitignore with testing artifacts and Claude settings
- Configure development tools (black, isort, flake8, mypy, pre-commit)
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