Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the pytorch-gradual-warmup-lr project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with Poetry configuration
  • Preserved existing metadata: Maintained version, description, and URLs from setup.py
  • Note: setup.py is kept for backward compatibility

Testing Dependencies

Added as development dependencies:

  • pytest ^8.0.0 - Core testing framework
  • pytest-cov ^5.0.0 - Coverage reporting
  • pytest-mock ^3.14.0 - Mocking utilities

Testing Configuration

Configured in pyproject.toml:

  • Test discovery: Configured to find tests in tests/ directory
  • Coverage settings:
    • Source: warmup_scheduler package
    • Reports: Terminal, HTML, and XML formats
    • Threshold: 80% (currently disabled due to PyTorch dependency)
  • Custom markers:
    • unit - For unit tests
    • integration - For integration tests
    • slow - For slow-running tests

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration objects
  • mock_optimizer - Mock PyTorch optimizer
  • mock_scheduler - Mock LR scheduler
  • capture_output - Stdout/stderr capture
  • mock_torch_module - Mock torch imports
  • sample_data - Test data provider
  • environment_vars - Environment variable management
  • mock_time - Time-related mocking

Development Commands

Both commands are configured to run tests:

  • poetry run test
  • poetry run tests

Additional Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • IDE files
    • Note that poetry.lock should be committed

How to Use

  1. Install Poetry (if not already installed):

    pip install poetry
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test
    # or
    poetry run tests
  4. Run tests with specific markers:

    poetry run pytest -m unit        # Run only unit tests
    poetry run pytest -m integration # Run only integration tests
    poetry run pytest -m "not slow"  # Skip slow tests
  5. View coverage report:

    # After running tests, open the HTML report
    open htmlcov/index.html

Notes

  • The validation tests currently skip tests that require PyTorch, as it's not included in the base dependencies
  • Coverage threshold is configured but not enforced during infrastructure setup
  • The testing infrastructure is ready for developers to start writing actual unit and integration tests
  • All pytest options remain available (e.g., -v for verbose, -k for keyword matching, etc.)

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Add PyTorch as a dependency when needed for actual tests

- Migrate from setup.py to Poetry-based dependency management
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage reporting and custom markers
- Create testing directory structure with unit/integration subdirs
- Add comprehensive shared fixtures in conftest.py
- Update .gitignore with testing and Claude-related entries
- 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