EnlightenGAN icon indicating copy to clipboard operation
EnlightenGAN copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Python 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: Created pyproject.toml with Poetry as the package manager
  • Dependency Migration: Migrated existing dependencies from requirement.txt to Poetry
  • Lock File: Generated poetry.lock to ensure reproducible builds

Testing Dependencies

Added the following testing tools as development dependencies:

  • pytest - Modern testing framework
  • pytest-cov - Coverage reporting plugin
  • pytest-mock - Mocking utilities

Testing Configuration

Configured pytest in pyproject.toml with:

  • Test discovery patterns
  • Coverage reporting with 80% threshold
  • HTML and XML coverage reports
  • Strict markers and configuration
  • Custom test markers: unit, integration, slow

Directory Structure

Created organized testing structure:

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

Shared Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration objects
  • sample_image_tensor - Test image tensors
  • mock_dataset - Mock dataset for testing
  • mock_dataloader - Mock dataloader
  • cleanup_gpu - GPU memory cleanup
  • mock_visdom - Mocked visualization
  • sample_options - Sample command line options
  • And more...

Additional Setup

  • Updated .gitignore with testing artifacts and Claude settings
  • Created validation tests to verify the infrastructure works correctly

How to Use

Installing Dependencies

poetry install

Running Tests

You can run tests using either:

poetry run pytest

Running Tests with Coverage

Coverage is enabled by default:

poetry run pytest

Running Specific Test Types

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests  
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Coverage Reports

  • HTML report: htmlcov/index.html
  • XML report: coverage.xml
  • Terminal report: Shown after test run

Notes

  • The project uses Poetry in non-package mode since it's not a distributable package
  • Coverage threshold is set to 80% - tests will fail if coverage drops below this
  • All test-related files are properly gitignored except the lock file
  • The infrastructure is ready for immediate use - developers can start writing tests right away

Validation

All validation tests pass successfully:

  • ✅ Testing dependencies installed
  • ✅ Directory structure created
  • ✅ Fixtures available and working
  • ✅ Test markers configured
  • ✅ Coverage reporting configured

llbbl avatar Jun 14 '25 16:06 llbbl