Skip to content

feat: Set up comprehensive Python testing infrastructure#83

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

feat: Set up comprehensive Python testing infrastructure#83
llbbl wants to merge 1 commit into
GooglingTheCancerGenome:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 3, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the SV-callers project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for developers to immediately start writing and running tests.

Changes Made

Package Management

  • Added Poetry configuration (pyproject.toml) with proper project metadata
  • Migrated dependencies from test-requirements.txt and environment.yaml
  • Set up development dependencies including pytest, pytest-cov, pytest-mock, and codacy-coverage

Testing Configuration

  • Configured pytest with comprehensive settings in pyproject.toml:
    • Test discovery patterns for files, classes, and functions
    • Coverage reporting with 50% threshold (HTML, XML, terminal)
    • Custom markers: unit, integration, slow
    • Strict configuration for markers and config validation

Directory Structure

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

Shared Testing Utilities

  • Comprehensive fixtures in conftest.py:
    • temp_dir: Temporary directory management
    • sample_config: Mock configuration objects
    • File fixtures: sample_fasta_file, sample_bed_file, etc.
    • mock_config_object: Structured mock for workflow configuration

Infrastructure Validation

  • Validation tests verify the entire setup:
    • pytest functionality and markers
    • Project structure validation
    • Package imports and coverage integration
    • Python version compatibility

Development Environment

  • Updated .gitignore with testing artifacts, IDE files, and Claude Code settings
  • Coverage configuration excluding test files, build artifacts, and virtual environments

Testing Instructions

Running Tests

# Activate virtual environment and run tests
source .venv/bin/activate
python -m pytest tests/ --no-cov  # Without coverage
python -m pytest tests/ -v        # With coverage and verbose output

# Run specific test types
python -m pytest -m unit tests/           # Unit tests only
python -m pytest -m integration tests/    # Integration tests only
python -m pytest -m slow tests/          # Slow tests only

Coverage Reports

  • Terminal output: Shows coverage summary with missing lines
  • HTML report: Generated in htmlcov/ directory
  • XML report: Generated as coverage.xml for CI integration

Dependencies Added

Production Dependencies

  • snakemake==6.15.3
  • tabulate==0.8.10
  • yatiml==0.7

Development Dependencies

  • pytest>=4.6 - Main testing framework
  • pytest-cov - Coverage reporting
  • pytest-mock - Mocking utilities
  • codacy-coverage - Code quality reporting

Configuration Notes

  • Coverage threshold: Set to 50% to allow gradual improvement
  • Python version: Requires Python 3.8+ (defined in pyproject.toml)
  • Virtual environment: Poetry creates .venv/ in project root
  • Poetry lock file: Generated automatically, should be committed

Next Steps

With this infrastructure in place, developers can:

  1. Start writing unit tests for workflow/helper_functions.py
  2. Add integration tests for the complete workflow
  3. Gradually increase coverage threshold as tests are added
  4. Use the provided fixtures to mock file system operations and configurations

🤖 Generated with Claude Code

- Add Poetry package manager with pyproject.toml configuration
- Migrate dependencies from test-requirements.txt and environment.yaml
- Configure pytest with coverage reporting, custom markers, and strict options
- Create organized test directory structure (tests/unit/, tests/integration/)
- Add comprehensive shared fixtures in conftest.py for testing workflow functions
- Set up .gitignore entries for testing artifacts and IDE files
- Add validation tests to verify infrastructure setup
- Configure 50% coverage threshold with HTML and XML reporting
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