DiverseEvol icon indicating copy to clipboard operation
DiverseEvol copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the diverse-evol project, providing developers with a ready-to-use testing environment. The setup migrates the project from Conda-only dependency management to Poetry while maintaining all existing dependencies.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with complete Poetry configuration
  • Dependency Migration: Migrated all dependencies from environment.yml to Poetry format
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration: Comprehensive pytest settings in pyproject.toml including:
    • 80% test coverage threshold with HTML/XML reporting
    • Custom markers: unit, integration, slow
    • Strict configuration with proper test discovery patterns
    • Coverage exclusions for test files and common directories

Directory Structure

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

Testing Features

  • Shared Fixtures: Comprehensive fixture library in conftest.py including:

    • Temporary directories and file management
    • Mock configurations for models, tokenizers, and APIs
    • Sample data fixtures (Alpaca format, test data, metrics)
    • Environment management and GPU mocking
    • Random seed reset for reproducible tests
  • Validation Tests: Complete test suite to verify infrastructure works correctly

  • Poetry Scripts: Easy-to-use commands (poetry run test and poetry run tests)

Development Environment

  • Updated .gitignore: Added comprehensive patterns for:
    • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
    • Virtual environments and build artifacts
    • IDE files and OS-specific files
    • Claude Code settings

How to Use

Running Tests

# Run all tests
poetry run test

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m "not slow"    # Skip slow tests

# Run with coverage report
poetry run pytest --cov

# Run specific test files
poetry run pytest tests/test_setup_validation.py -v

Writing Tests

  1. Unit tests: Place in tests/unit/
  2. Integration tests: Place in tests/integration/
  3. Use fixtures: Leverage the comprehensive fixture library in conftest.py
  4. Mark tests: Use @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

Validation Results

The testing infrastructure has been validated with:

  • ✅ Basic pytest functionality working
  • ✅ Project structure validation
  • ✅ Custom markers and fixtures functional
  • ✅ Poetry commands (poetry run test) working correctly
  • ✅ Coverage reporting configured properly

Notes

  • The existing environment.yml is preserved for backwards compatibility
  • All original dependencies are maintained in Poetry format
  • Testing dependencies are properly isolated as development dependencies
  • The setup is ready for immediate use - developers can start writing tests right away

Dependencies Added

  • pytest ^7.4.0 - Main testing framework
  • pytest-cov ^4.1.0 - Coverage reporting
  • pytest-mock ^3.11.1 - Mocking utilities

🤖 Generated with Claude Code

llbbl avatar Sep 02 '25 17:09 llbbl