Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry#27

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

feat: Add comprehensive Python testing infrastructure with Poetry#27
llbbl wants to merge 1 commit intoKiteretsu77:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the anime enhancement project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with coverage reporting.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Python Version: Set to Python 3.10+ for compatibility with scipy and other dependencies

Testing Dependencies

Added as development dependencies:

  • pytest ^8.0.0 - Main testing framework
  • pytest-cov ^4.1.0 - Coverage reporting
  • pytest-mock ^3.12.0 - Mocking utilities

Testing Configuration

Pytest Configuration

  • Test discovery patterns for test_*.py files
  • Strict markers and configuration enforcement
  • Coverage integration with fail threshold at 80%
  • Custom markers:
    • unit - For fast, isolated unit tests
    • integration - For tests requiring external resources
    • slow - For long-running tests

Coverage Configuration

  • Source directories: architecture, degradation, loss, test_code, train_code
  • Multiple report formats: terminal, HTML (htmlcov/), and XML (coverage.xml)
  • Branch coverage enabled
  • Exclusions for test files, cache, and virtual environments

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory for test files
  • sample_image - Generate test images
  • sample_tensor - PyTorch tensor fixtures
  • mock_config - Configuration dictionary fixture
  • mock_model_weights - Mock model weights file
  • reset_torch_seed - Reproducible random seeds
  • device - GPU/CPU device selection
  • cleanup_gpu - GPU memory cleanup

Development Scripts

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work)

Updated .gitignore

Added patterns for:

  • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
  • Claude settings (.claude/)
  • Poetry/build artifacts
  • Virtual environments
  • IDE files
  • OS-specific files

Usage Instructions

  1. Install dependencies:

    poetry install --with dev
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test categories:

    poetry run pytest -m unit          # Only unit tests
    poetry run pytest -m integration   # Only integration tests
    poetry run pytest -m "not slow"    # Skip slow tests
  4. View coverage reports:

    • Terminal: Shown automatically after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The infrastructure is ready for immediate use - developers can start writing tests in the appropriate directories
  • Coverage threshold is set to 80% but currently shows 0% as only validation tests exist
  • All pytest options remain available (e.g., -v for verbose, -x to stop on first failure)
  • The Poetry lock file (poetry.lock) is committed to ensure reproducible environments

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with 80% threshold and HTML/XML output
- Create test directory structure with shared fixtures in conftest.py
- Update .gitignore with testing and development patterns
- Add validation tests to verify infrastructure setup
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