Skip to content

feat: Add comprehensive Python testing infrastructure#24

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

feat: Add comprehensive Python testing infrastructure#24
llbbl wants to merge 1 commit intoibrahimethemhamamci:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 2, 2025

Add Comprehensive Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the CT2Rep project, providing a robust foundation for writing and running tests across all project modules.

Changes Made

Package Management

  • Set up Poetry as the primary package manager with pyproject.toml
  • Migrated dependencies from existing setup.py to Poetry configuration
  • Added comprehensive project metadata and build system configuration

Testing Dependencies

  • Added pytest ecosystem: pytest, pytest-cov, pytest-mock
  • Configured as development dependencies (not production)
  • All dependencies installed and verified working

Testing Configuration

  • Comprehensive pytest settings in pyproject.toml:

    • Test discovery patterns for files, classes, and functions
    • Coverage reporting with 80% threshold
    • HTML, XML, and terminal coverage reports
    • Custom test markers: unit, integration, slow
    • Strict configuration and marker enforcement
  • Coverage configuration:

    • Source directories: CT2Rep, CT2RepLong, ctvit
    • Exclusion patterns for test files, cache, virtual environments
    • Detailed reporting with missing line information

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (tests/conftest.py)

Comprehensive fixture library including:

  • File system: temporary directories, sample file paths
  • Configuration: mock config objects with realistic parameters
  • PyTorch: sample tensors, mock models, devices, optimizers
  • Data handling: mock tokenizers, dataloaders, numpy arrays
  • Medical imaging: sample CT image paths, radiology report text
  • Metrics: mock evaluation metrics for model testing
  • Reproducibility: automatic random seed setting

Development Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative test command
  • Both commands support all standard pytest options and flags

Infrastructure Validation

  • 15 validation tests ensure all components work correctly
  • Tests verify fixtures, PyTorch integration, mock objects, and project structure
  • All tests pass, confirming proper setup

Project Files

  • .gitignore: Comprehensive exclusions for testing artifacts, Python cache, IDE files, and project outputs
  • Preserved existing: README.md and project structure unchanged

Instructions for Running Tests

Basic Usage

# Install dependencies
poetry install

# Run all tests
poetry run test

# Run with verbose output
poetry run test -v

# Run specific test categories
poetry run test -m unit
poetry run test -m integration
poetry run test -m slow

# Run with coverage
poetry run test --cov

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

Coverage Reporting

  • Terminal: Shows missing lines and coverage percentage
  • HTML: Detailed reports in htmlcov/ directory
  • XML: Machine-readable reports in coverage.xml

Notes

  • Poetry chosen over UV due to its maturity and ecosystem support
  • 80% coverage threshold can be adjusted based on project needs
  • Validation tests included to verify infrastructure works correctly
  • Flexible fixture system supports various testing scenarios
  • Lock files preserved in git for reproducible builds
  • No actual unit tests written - infrastructure only as requested

Ready for Development

The testing infrastructure is now complete and ready for developers to start writing comprehensive tests for all project modules. The foundation supports unit tests, integration tests, mocking, coverage analysis, and automated validation.

Set up complete testing environment with Poetry, pytest, and coverage reporting.
Includes structured test directories, shared fixtures, and validation 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