princess
princess copied to clipboard
feat: Set up comprehensive Python testing infrastructure
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 frameworkpytest-cov(v4.1.0+) - Coverage reportingpytest-mock(v3.11.0+) - Mocking utilities
Testing Configuration
- Pytest Configuration: Comprehensive setup in
pyproject.tomlincluding:- 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 creationtemp_file: Temporary file with contentsample_vcf_content: VCF file content for bioinformatics testingsample_vcf_file: Complete VCF file fixturemock_args: Mock argument parsercapture_stdout: Output capture utilityenv_backup: Environment variable backup/restoreworking_directory: Temporary working directory
Infrastructure Validation
- Validation Tests: Created
test_infrastructure.pyto 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.xmlfor 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:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing scenarios
- Run tests with comprehensive coverage reporting
- Mark tests with appropriate markers for selective execution
The testing infrastructure is ready for immediate use and follows Python testing best practices.