Skip to content

Comments

feat: Set up comprehensive Python testing infrastructure#1

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

feat: Set up comprehensive Python testing infrastructure#1
llbbl wants to merge 1 commit intoshreyansh26:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 1, 2025

Set up Complete Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the speculative sampling project using Poetry as the package manager. The setup includes all necessary testing dependencies, configuration, and validation tests to enable immediate test development.

Changes Made

Package Management

  • Added Poetry configuration (pyproject.toml) with project metadata and dependencies
  • Migrated dependencies from existing project structure to Poetry format
  • Configured project dependencies: torch, transformers, tqdm
  • Added development dependencies: pytest, pytest-cov, pytest-mock

Testing Configuration

  • pytest configuration with test discovery, coverage settings, and custom markers
  • Coverage reporting configured for HTML, XML, and terminal output with 80% threshold
  • Custom markers for organizing tests: unit, integration, slow
  • Poetry scripts for convenient test execution: poetry run test and poetry run tests

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test utilities
├── test_infrastructure.py   # Validation tests for testing setup
├── unit/                    # Unit test directory
│   └── __init__.py
└── integration/             # Integration test directory
    └── __init__.py

Testing Utilities

  • Comprehensive fixtures in conftest.py including:
    • Mock PyTorch components (tensors, models, tokenizers)
    • Temporary directory handling
    • Mock transformers components to avoid loading real models
    • Sampling configuration fixtures
    • Output suppression utilities

Validation

  • Infrastructure validation tests that verify all components work correctly
  • Marker functionality testing to ensure test organization works
  • Mock component testing to validate test fixtures
  • Coverage reporting validation with proper exclusions

Testing Instructions

Run All Tests

poetry run test
# or
poetry run tests
# or
poetry run pytest

Run Specific Test Types

# Run only unit tests
poetry run pytest -m "unit"

# Run only integration tests  
poetry run pytest -m "integration"

# Run without slow tests
poetry run pytest -m "not slow"

Coverage Reports

# Run with coverage (default)
poetry run pytest

# Generate HTML coverage report
poetry run pytest --cov-report=html

# View coverage report
open htmlcov/index.html

Test Discovery

Tests are automatically discovered in the tests/ directory following these patterns:

  • Files: test_*.py or *_test.py
  • Classes: Test*
  • Functions: test_*

Configuration Details

Dependencies Added

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

Coverage Configuration

  • Source: All project files (excluding tests and build artifacts)
  • Threshold: 80% minimum coverage required
  • Reports: HTML (htmlcov/), XML (coverage.xml), and terminal
  • Exclusions: Standard exclusions for debugging, abstract methods, and main blocks

Files Updated

  • pyproject.toml - New file with complete project configuration
  • .gitignore - Added testing artifacts and Claude Code entries

Validation Results

✅ All infrastructure validation tests pass (10/10)
✅ Poetry installation successful
✅ Test markers working correctly
✅ Coverage reporting functional
✅ Mock fixtures operational
✅ Both poetry run test and poetry run tests commands work

Notes

  • The setup uses Poetry for dependency management as no existing package manager was detected
  • All testing dependencies are isolated in the [tool.poetry.group.test.dependencies] section
  • The configuration is ready for immediate use - developers can start writing tests right away
  • Mock fixtures are provided to avoid loading large ML models during testing
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml if needed

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures in conftest.py
  4. Run tests with poetry run test
  5. Generate coverage reports automatically

- Add Poetry package manager with pyproject.toml configuration
- Install testing dependencies: pytest, pytest-cov, pytest-mock
- Configure pytest with coverage reporting and custom markers
- Create structured test directories (tests/, unit/, integration/)
- Add comprehensive conftest.py with shared fixtures for ML testing
- Set up validation tests to verify infrastructure functionality
- Configure coverage reporting with 80% threshold and HTML/XML output
- Update .gitignore with testing and Claude Code entries
- Add Poetry scripts for convenient 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