Skip to content

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

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

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

Conversation

@llbbl
Copy link

@llbbl llbbl commented Aug 23, 2025

Add Complete Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Restore RWKV medical imaging project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with complete project metadata and dependency management
  • Dependencies: Added all required project dependencies including:
    • Core: torch, torchvision, numpy, pandas, einops, simpleitk
    • Testing: pytest, pytest-cov, pytest-mock, pytest-xdist
    • Development: black, isort, flake8, mypy, pre-commit

Testing Configuration

  • pytest Settings: Configured comprehensive pytest options including:

    • Coverage reporting with HTML and XML output
    • Custom markers for unit, integration, and slow tests
    • Strict mode with verbose output
    • Test discovery patterns
  • Coverage Settings: Set up coverage configuration with:

    • Source code coverage tracking
    • Exclusion patterns for test files and generated code
    • HTML and XML report generation
    • Branch coverage analysis

Directory Structure

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

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • Temporary Resources: temp_dir, isolated_filesystem
  • Configuration: mock_config with model/training/data settings
  • Data Fixtures: sample tensors, numpy arrays, PIL images, medical data
  • Model Mocks: mock_model, mock_dataloader, mock_optimizer, mock_scheduler
  • Testing Utilities: random_seed, capture_stdout, mock_tqdm
  • CUDA Management: cleanup_cuda fixture for memory management

Additional Setup

  • Git Ignore: Updated .gitignore with Python, testing, and Claude-specific patterns
  • Test Runner: Created run_tests.sh helper script for easy test execution
  • Validation Suite: Comprehensive test suite to verify all infrastructure components work

How to Use

Install Dependencies

poetry install --with dev

Run Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py

# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Using the helper script
./run_tests.sh

View Coverage Reports

  • Terminal: Coverage summary is shown after each test run
  • HTML Report: Open htmlcov/index.html in a browser
  • XML Report: Available at coverage.xml for CI/CD integration

Testing Infrastructure Validation

The PR includes a validation test suite that verifies:

  • All dependencies are properly installed
  • Test markers work correctly
  • All fixtures function as expected
  • Project modules can be imported
  • Coverage reporting generates properly

All validation tests pass successfully (33 passed, 1 skipped due to CUDA compilation requirement).

Notes

  • Coverage threshold is currently set to 0% as this PR only sets up infrastructure
  • Once actual unit tests are written, update the threshold in pyproject.toml (line 47)
  • The model import test is skipped as it requires CUDA kernel compilation
  • Poetry lock file is included and should be committed for reproducible builds

Next Steps

Developers can now immediately start writing tests using this infrastructure:

  1. Create test files in tests/unit/ or tests/integration/
  2. Use the provided fixtures from conftest.py
  3. Run tests with poetry run pytest
  4. Monitor coverage to ensure code quality

- Configure Poetry as package manager with pyproject.toml
- Add testing dependencies (pytest, pytest-cov, pytest-mock, pytest-xdist)
- Configure pytest with coverage reporting and custom markers
- Create tests/ directory structure with unit and integration subdirectories
- Add comprehensive shared fixtures in conftest.py
- Create validation test suite to verify infrastructure
- Update .gitignore with testing and Claude-specific entries
- Add all required project dependencies (torch, einops, simpleitk, etc.)
- Create run_tests.sh helper script for test execution
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