SimMIM icon indicating copy to clipboard operation
SimMIM copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the SimMIM project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.

Changes Made

Package Management

  • Poetry Configuration: Set up Poetry as the package manager with pyproject.toml
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Package Mode: Configured as package-mode = false for dependency management only

Testing Dependencies

Added the following development dependencies:

  • pytest (^7.4.0) - Core testing framework
  • pytest-cov (^4.1.0) - Coverage reporting
  • pytest-mock (^3.11.0) - Mocking utilities

Testing Configuration

Configured pytest in pyproject.toml with:

  • Test discovery patterns for test_*.py and *_test.py files
  • Coverage reporting for data, models, and root Python files
  • Multiple coverage output formats (terminal, HTML, XML)
  • Strict markers and configuration
  • Custom test markers: unit, integration, slow

Directory Structure

Created proper testing directory structure:

tests/
├── __init__.py
├── conftest.py
├── test_setup_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory for test files
  • mock_config - Mock configuration object
  • sample_yaml_config - Sample YAML configuration file
  • mock_dataset - Mock dataset object
  • mock_model - Mock model object
  • sample_image_tensor - Sample image tensor for testing
  • captured_output - Capture stdout/stderr for testing
  • reset_modules - Auto-reset modules between tests

Additional Files

  • test.sh: Simple shell script for running tests
  • Validation Tests: Created test_setup_validation.py to verify the testing infrastructure

Configuration Updates

  • Updated .gitignore to include .claude/* for Claude-specific settings

How to Use

Install Dependencies

poetry install

Run Tests

You can run tests using any of these methods:

# Using Poetry directly
poetry run pytest

# Using the test script
./test.sh

# Run specific tests
poetry run pytest tests/test_setup_validation.py

# Run with coverage
poetry run pytest --cov

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

Coverage Reports

Coverage reports are generated in multiple formats:

  • Terminal output with missing lines
  • HTML report in htmlcov/ directory
  • XML report as coverage.xml

Notes

  • The coverage threshold requirement has been removed from the initial setup to allow for gradual test development
  • The project is configured to exclude test files and __pycache__ from coverage reporting
  • All validation tests are passing, confirming the infrastructure is properly set up
  • The _pil_interp import issue from timm is handled gracefully in the validation tests

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 needs
  4. Run tests with coverage to track testing progress

llbbl avatar Jun 17 '25 11:06 llbbl