Skip to content

feat: Set up comprehensive Python testing infrastructure#44

Open
llbbl wants to merge 1 commit intoTencent-Hunyuan:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure#44
llbbl wants to merge 1 commit intoTencent-Hunyuan:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 20, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the InstantCharacter project, providing all the necessary tooling and configuration for developers to write and run tests effectively.

Changes Made

Package Management

  • Poetry configured as the package manager
  • Created pyproject.toml with:
    • Project metadata and dependencies
    • Testing dependencies (pytest, pytest-cov, pytest-mock)
    • Python 3.9+ requirement to match dependency constraints

Testing Configuration

  • pytest configuration with:
    • Test discovery patterns for multiple naming conventions
    • Coverage settings with 80% threshold
    • HTML and XML coverage report generation
    • Custom markers: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
    • Strict marker enforcement

Project Structure

  • Created organized test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── unit/               # Unit tests
    │   └── __init__.py
    └── integration/        # Integration tests
        └── __init__.py
    
  • Made models/ directory a proper Python package with __init__.py

Shared Fixtures (conftest.py)

Comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • mock_image - PIL Image mocks
  • mock_tensor_image, mock_latents - PyTorch tensor mocks
  • mock_config, mock_pipeline_config - Configuration mocks
  • mock_model_components - Model component mocks
  • mock_huggingface_hub - HuggingFace Hub download mocks
  • capture_stdout - Output capture for testing print statements
  • benchmark_timer - Simple performance benchmarking
  • And more...

All fixtures gracefully handle missing optional dependencies.

Development Experience

  • Poetry scripts configured: both poetry run test and poetry run tests work
  • Updated .gitignore with comprehensive Python/testing patterns
  • Added validation tests to verify the infrastructure works correctly

How to Use

  1. Install dependencies (if Poetry is available):

    poetry install --only dev
  2. Run tests:

    # Using Poetry scripts
    poetry run test
    # or
    poetry run tests
    
    # Direct pytest command
    poetry run pytest
    
    # Run specific test markers
    poetry run pytest -m unit
    poetry run pytest -m integration
  3. Run with coverage:

    poetry run pytest --cov
  4. Run validation tests:

    poetry run pytest tests/test_setup_validation.py -v

Notes

  • The infrastructure is designed to work even without all dependencies installed
  • Coverage is temporarily disabled in the default configuration to allow testing without full dependencies
  • All test fixtures handle missing dependencies gracefully with pytest.skip()
  • The setup follows Python testing best practices and conventions

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with coverage reporting
  5. Use test markers to organize and filter tests

The testing infrastructure is ready for immediate use!

- Add Poetry package manager with pyproject.toml configuration
- Configure pytest with coverage, markers, and custom settings
- Create test directory structure with unit/integration organization
- Add comprehensive shared fixtures in conftest.py
- Update .gitignore with testing and build artifacts
- Add validation tests to verify infrastructure setup
- Configure Poetry scripts for 'test' and 'tests' commands
- Make models directory a proper Python package
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