Skip to content

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

Open
llbbl wants to merge 1 commit intoc-he:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#15
llbbl wants to merge 1 commit intoc-he:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 2, 2025

Set up Python Testing Infrastructure with Poetry

Summary

This PR establishes a complete testing infrastructure for the PERM project, migrating from requirements.txt to Poetry for dependency management and adding comprehensive testing capabilities.

Changes Made

Package Management

  • Added Poetry configuration via pyproject.toml with project metadata and dependencies
  • Migrated existing dependencies from requirements.txt to Poetry format
  • Set up development dependencies including pytest, pytest-cov, and pytest-mock
  • Created Poetry script commands for easy test execution (poetry run test and poetry run tests)

Testing Configuration

  • Configured pytest with comprehensive settings in pyproject.toml:

    • Test discovery patterns for various naming conventions
    • Coverage reporting with 80% threshold requirement
    • HTML and XML coverage report generation
    • Custom test markers (unit, integration, slow)
    • Strict configuration and verbose output
  • Set up coverage reporting with:

    • Source directory inclusion (src/)
    • Proper exclusions for test files and common patterns
    • Multiple output formats (terminal, HTML, XML)
    • Configurable coverage thresholds

Directory Structure

  • Created organized testing directories:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures and configuration
    ├── unit/
    │   └── __init__.py
    ├── integration/
    │   └── __init__.py
    └── test_setup_validation.py
    

Shared Testing Utilities

  • Added comprehensive fixtures in conftest.py:
    • temp_dir: Temporary directory management
    • mock_config: Mock configuration data
    • sample_hair_data: Generated hair data for testing
    • mock_model_weights: Mock neural network weights
    • sample_image_data: Sample image data
    • Environment setup and device configuration

Validation Tests

  • Created validation test suite (test_setup_validation.py) to verify:
    • Basic pytest functionality
    • Coverage configuration
    • Custom test markers
    • Source code importability
    • Fixture functionality
    • Mocking utilities
    • Parametrized testing

Additional Improvements

  • Updated .gitignore with testing artifacts:
    • Coverage reports and cache files
    • Claude Code settings
    • IDE and OS-specific files
  • Maintained poetry.lock in version control for reproducible builds

Usage Instructions

Running Tests

# Install dependencies (first time setup)
poetry install

# Run all tests
poetry run test

# Run with coverage (default behavior)
poetry run pytest

# Run specific test categories
poetry run pytest -m unit          # Unit tests only  
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m "not slow"    # Skip slow tests

# Run tests without coverage for faster execution
poetry run pytest --no-cov

# Generate HTML coverage report
poetry run pytest
open htmlcov/index.html

Test Organization

  • Unit tests: Fast, isolated tests → tests/unit/
  • Integration tests: Component interaction tests → tests/integration/
  • Slow tests: Mark with @pytest.mark.slow for selective execution

Writing Tests

Use the provided fixtures in conftest.py for common test scenarios:

def test_example(temp_dir, mock_config, sample_hair_data):
    # temp_dir: temporary directory for file operations
    # mock_config: configuration dictionary
    # sample_hair_data: numpy arrays with hair data
    pass

Validation Results

All validation tests pass successfully:

  • ✅ Basic pytest functionality
  • ✅ Coverage configuration
  • ✅ Custom markers (unit, integration, slow)
  • ✅ Source code importability
  • ✅ Shared fixtures and utilities
  • ✅ Mocking capabilities

Dependencies Added

  • pytest ^7.4.0 - Main testing framework
  • pytest-cov ^4.1.0 - Coverage reporting
  • pytest-mock ^3.11.1 - Mocking utilities
  • numpy ^1.21.0 - For test data generation

Next Steps

The testing infrastructure is now ready for development. Developers can:

  1. Start writing unit tests in tests/unit/
  2. Add integration tests in tests/integration/
  3. Use the provided fixtures and markers
  4. Maintain the 80% coverage threshold
  5. Run tests with poetry run test

🤖 Generated with Claude Code

- Add Poetry configuration with pyproject.toml and migrate dependencies
- Configure pytest with coverage reporting (80% threshold) and custom markers
- Create organized testing directory structure (tests/, tests/unit/, tests/integration/)
- Add shared fixtures in conftest.py for common test data and utilities
- Include validation tests to verify infrastructure setup
- Update .gitignore with testing artifacts and Claude Code settings
- Set up Poetry script commands for running tests (test/tests)
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

Comments