princess icon indicating copy to clipboard operation
princess copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the Princess bioinformatics project, providing developers with a robust foundation for writing and running tests.

Changes Made

Package Management

  • Poetry Setup: Configured Poetry as the package manager with pyproject.toml
  • Dependency Management: Added testing dependencies as development dependencies:
    • pytest (v7.4.0+) - Main testing framework
    • pytest-cov (v4.1.0+) - Coverage reporting
    • pytest-mock (v3.11.0+) - Mocking utilities

Testing Configuration

  • Pytest Configuration: Comprehensive setup in pyproject.toml including:
    • Test discovery patterns for flexible test file naming
    • Coverage reporting with 80% threshold
    • HTML, XML, and terminal coverage reports
    • Strict markers and configuration validation
    • Custom markers: unit, integration, slow

Directory Structure

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

Testing Utilities

  • Shared Fixtures (tests/conftest.py):
    • temp_dir: Temporary directory creation
    • temp_file: Temporary file with content
    • sample_vcf_content: VCF file content for bioinformatics testing
    • sample_vcf_file: Complete VCF file fixture
    • mock_args: Mock argument parser
    • capture_stdout: Output capture utility
    • env_backup: Environment variable backup/restore
    • working_directory: Temporary working directory

Infrastructure Validation

  • Validation Tests: Created test_infrastructure.py to verify:
    • Pytest functionality
    • Fixture availability and functionality
    • Custom marker availability
    • Coverage reporting capability

Project Configuration

  • Updated .gitignore: Added testing-related entries and Claude Code settings
  • Coverage Settings: Configured to exclude appropriate files and directories

Instructions for Running Tests

Basic Commands

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration

# Run without coverage (faster for development)
poetry run pytest --no-cov

# Generate HTML coverage report
poetry run pytest --cov --cov-report=html

Coverage Reports

  • Terminal: Shows coverage summary after each test run
  • HTML: Generated in htmlcov/ directory
  • XML: Generated as coverage.xml for CI/CD integration

Development Notes

Dependency Choices

  • Poetry: Selected as package manager for better dependency resolution and modern Python packaging
  • pytest: Industry standard testing framework with excellent plugin ecosystem
  • Coverage Threshold: Set to 80% to ensure good test coverage while remaining achievable

Directory Organization

  • Separate unit/integration: Allows for different testing strategies and CI/CD pipeline optimization
  • Shared fixtures: Reduces code duplication and provides consistent test utilities

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 comprehensive coverage reporting
  5. Mark tests with appropriate markers for selective execution

The testing infrastructure is ready for immediate use and follows Python testing best practices.

llbbl avatar Sep 03 '25 17:09 llbbl