OnePose icon indicating copy to clipboard operation
OnePose copied to clipboard

feat: Add complete Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Complete Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the OnePose Python 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
  • Dependencies: Migrated existing dependencies from requirements.txt
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration: Configured in pyproject.toml with:
    • Test discovery patterns (test_*.py, *_test.py)
    • Coverage settings with 80% threshold
    • HTML and XML coverage report generation
    • Custom test markers: unit, integration, slow
    • Strict mode enabled for better error detection

Project Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • temp_file: Temporary file creation
  • mock_config: Mock configuration dictionary
  • sample_yaml_config: YAML config file generation
  • sample_image_data: Sample image metadata
  • sample_annotation_data: Sample annotation data
  • mock_model_checkpoint: Mock checkpoint file
  • environment_setup: Environment variable setup
  • cleanup_wandb: Disable wandb during tests
  • mock_dataset_structure: Mock dataset directory structure
  • capture_logs: Log capture fixture

Additional Setup

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Claude settings (.claude/*)
    • Python build artifacts and virtual environments
  • Created validation tests to verify the infrastructure works

How to Use

Install Dependencies

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

# Install project dependencies
poetry install

# Install only development dependencies
poetry install --only dev

Run Tests

# Run all tests with coverage
poetry run pytest

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

# Run with verbose output
poetry run pytest -v

# Generate 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
    def test_something():
        pass
    
    @pytest.mark.integration
    def test_integration():
        pass
    
    @pytest.mark.slow
    def test_slow_operation():
        pass
    

Notes

  • The testing infrastructure is set up but doesn't include actual unit tests for the codebase
  • Some project dependencies may have compatibility issues on certain platforms
  • Poetry lock file will be generated on first install
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml

Next Steps

  1. Install dependencies with poetry install
  2. Run validation tests to ensure setup works
  3. Start writing unit tests for existing code
  4. Set up CI/CD to run tests automatically

llbbl avatar Jun 23 '25 00:06 llbbl