Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry#57

Open
llbbl wants to merge 1 commit into
lizhe00:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#57
llbbl wants to merge 1 commit into
lizhe00:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 14, 2025

Python Testing Infrastructure Setup

Summary

This PR sets up a comprehensive testing infrastructure for the AvatarREx project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Initialized Poetry as the primary package manager
    • Created pyproject.toml with all project dependencies
    • Migrated dependencies from requirements.txt to Poetry format
    • Updated dependency versions for Python 3.11 compatibility
    • Configured project in package-mode=false for development

Testing Framework

  • pytest Configuration:
    • Added pytest, pytest-cov, and pytest-mock as development dependencies
    • Configured test discovery patterns and paths
    • Set up coverage reporting with HTML and XML outputs
    • Added custom test markers: unit, integration, and slow
    • Configured strict mode and helpful output options

Testing Structure

  • Directory Structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── test_infrastructure.py  # Validation tests
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • sample_config: Sample configuration dictionary
  • mock_config_file: Temporary YAML config file
  • sample_tensor_data: PyTorch tensor test data
  • sample_numpy_data: NumPy array test data
  • mock_model_checkpoint: Mock PyTorch checkpoint
  • mock_data_file: Mock NPZ data file
  • mock_obj_file: Mock OBJ mesh file
  • mock_environment_variables: Environment variable mocking
  • reset_random_seeds: Automatic seed resetting for reproducibility
  • device: CPU/CUDA device selection
  • cleanup_gpu_memory: GPU memory cleanup

Coverage Configuration

  • Source code coverage tracking enabled
  • Exclusions for test files, virtual environments, and build artifacts
  • HTML coverage reports in htmlcov/ directory
  • XML coverage report for CI integration
  • Coverage threshold set to 80% (currently commented for initial setup)

Additional Updates

  • .gitignore Updates:
    • Added testing artifacts: .pytest_cache/, htmlcov/, coverage.xml
    • Added Claude settings: .claude/*
    • Added additional virtual environment patterns
    • Added IDE and build artifact exclusions

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests with coverage
poetry run pytest

# Run tests without coverage
poetry run pytest --no-cov

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

# Run tests in specific directory
poetry run pytest tests/unit

View Coverage Reports

  • HTML Report: Open htmlcov/index.html in a browser
  • Terminal Report: Automatically shown after test run
  • XML Report: Available at coverage.xml for CI tools

Notes

  • pytorch3d: Temporarily commented out due to installation issues. Can be installed manually if needed.
  • Python Version: Updated dependencies to support Python 3.11
  • Coverage Threshold: The 80% coverage requirement is currently commented out to allow initial setup without failing builds

Validation

All validation tests pass successfully, confirming that:

  • pytest is properly installed and configured
  • All fixtures work correctly
  • Test markers are functional
  • Coverage reporting generates properly
  • Directory structure is correct

The testing infrastructure is now ready for developers to start writing unit and integration tests for the codebase.

- Initialized Poetry as package manager with pyproject.toml configuration
- Migrated dependencies from requirements.txt to Poetry
- Added testing dependencies: pytest, pytest-cov, pytest-mock
- Configured pytest with coverage reporting (HTML/XML formats)
- Created test directory structure with unit/integration subdirectories
- Added comprehensive shared fixtures in conftest.py
- Created validation tests to verify infrastructure works correctly
- Updated .gitignore with testing artifacts and Claude settings
- Set up test markers for unit, integration, and slow tests
- Configured coverage exclusions and thresholds
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