Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 4, 2025

Add Comprehensive Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the FSDP optimizers project, providing a ready-to-use testing environment for developers.

Changes Made

Package Management

  • Added Poetry configuration in pyproject.toml with complete project metadata
  • Migrated dependencies from setup.py to Poetry format
  • Fixed module imports to use relative imports for proper package structure

Testing Framework Setup

  • Added testing dependencies: pytest, pytest-cov, pytest-mock
  • Configured pytest in pyproject.toml with:
    • Test discovery patterns for automatic test detection
    • Coverage reporting with 80% threshold requirement
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow
    • Strict configuration for robust testing

Directory Structure

Created complete testing directory structure:

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

Testing Configuration

  • Coverage configuration with source inclusion/exclusion rules
  • Shared fixtures in conftest.py including:
    • temp_dir: Temporary directory management
    • mock_config: Mock configuration objects
    • sample_tensor: Sample PyTorch tensors
    • sample_model: Simple neural network models
    • optimizer_params: Standard optimizer parameters
    • random_seed: Reproducible random state
    • mock_fsdp_model: Mock FSDP models

Infrastructure Improvements

  • Updated .gitignore with comprehensive Python exclusions
  • Fixed import issues in optimizer modules (kron.py, kron_mars.py, muon.py, soap.py)
  • Added validation tests to verify the setup works correctly

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run Tests by Category

# Unit tests only
poetry run pytest -m unit

# Integration tests only  
poetry run pytest -m integration

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

Coverage Reports

# Terminal coverage report
poetry run pytest --cov-report=term-missing

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

Validation

The setup includes validation tests that verify:

  • ✅ All optimizer classes can be imported
  • ✅ PyTorch and NumPy are available
  • ✅ Pytest fixtures work correctly
  • ✅ Test markers function properly
  • ✅ Coverage reporting generates correctly

Notes

  • Poetry lock file: poetry.lock is tracked in git for reproducible builds
  • Coverage threshold: Set to 80% - can be adjusted in pyproject.toml
  • Test structure: Ready for developers to add unit and integration tests
  • Fixtures: Comprehensive shared fixtures available for consistent testing

This infrastructure provides a solid foundation for test-driven development and maintains high code quality standards.

- Set up Poetry package manager with pyproject.toml configuration
- Migrated dependencies from setup.py to Poetry (torch, numpy)
- Added testing dependencies: pytest, pytest-cov, pytest-mock
- Created complete test directory structure (tests/, unit/, integration/)
- Configured pytest with coverage reporting (80% threshold, HTML/XML output)
- Added custom test markers (unit, integration, slow)
- Fixed relative imports in fsdp_optimizers modules
- Created shared pytest fixtures for common testing scenarios
- Added validation tests to verify infrastructure setup
- Updated .gitignore with comprehensive Python/testing exclusions
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