Skip to content

feat: Set up complete Python testing infrastructure with Poetry - #25

Open
llbbl wants to merge 1 commit into
timgaripov:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up complete Python testing infrastructure with Poetry#25
llbbl wants to merge 1 commit into
timgaripov:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Jun 17, 2025

Copy link
Copy Markdown

Set Up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the PyTorch SWA-Gaussian project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the project's package manager
  • Dependencies: Added core project dependencies (torch, torchvision, tabulate)
  • Dev Dependencies: Added testing tools (pytest, pytest-cov, pytest-mock) as development dependencies

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with HTML and XML outputs
    • Added custom markers for test categorization (unit, integration, slow)
    • Enabled strict mode and comprehensive error reporting
  • Coverage Settings:

    • Source coverage for models, utils, and train modules
    • Branch coverage enabled
    • Exclusion patterns for test files and virtual environments
    • Coverage threshold set to 20% (adjustable based on project needs)

Directory Structure

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

Testing Utilities

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • mock_model: Mock PyTorch model for testing
  • mock_optimizer: Mock optimizer
  • mock_dataloader: Mock data loader with sample data
  • sample_checkpoint_data: Sample checkpoint structure
  • mock_args: Mock command-line arguments
  • cuda_available: CUDA availability check
  • small_model: Simple neural network for testing
  • reset_random_seeds: Reproducible random seeds
  • capture_stdout: Output capture utilities
  • mock_time: Time mocking for consistent measurements

Additional Updates

  • Code Fixes: Updated deprecated async=True to non_blocking=True in utils.py for Python 3.8+ compatibility
  • .gitignore Updates: Added entries for testing artifacts, Claude settings, and common development files

Usage Instructions

Install Dependencies

poetry install

Run Tests

Two equivalent commands are available:

poetry run test    # Run all tests with coverage
poetry run tests   # Alternative command

Run Tests Without Coverage

poetry run test --no-cov

Run Specific Test Markers

poetry run test -m unit          # Run only unit tests
poetry run test -m integration   # Run only integration tests
poetry run test -m "not slow"    # Skip slow tests

Run Specific Test Files

poetry run test tests/test_infrastructure_validation.py

Generate Coverage Reports

After running tests, coverage reports are available in:

  • Terminal output (with missing lines)
  • htmlcov/index.html (HTML report)
  • coverage.xml (XML report for CI/CD)

Notes

  • The testing infrastructure is now ready for developers to add unit and integration tests
  • Coverage threshold is currently set to 20% to allow for gradual test implementation
  • All pytest standard options are available through the Poetry commands
  • The validation test file demonstrates various testing patterns and fixture usage

- Initialize Poetry package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure comprehensive pytest and coverage settings
- Create tests directory structure with unit/integration subdirectories
- Add shared fixtures in conftest.py for common testing patterns
- Update .gitignore with testing and Claude-specific entries
- Fix deprecated async=True syntax in utils.py for Python 3.8+ compatibility
- Add validation tests to verify infrastructure setup
@izmailovpavel

Copy link
Copy Markdown
Collaborator

Hi, could you provide a bit more context on what this PR is? From a quick look, it seems like the tests are not actually testing for anything specific to the SWA implementation in this package? Overall, the implementation of SWA has been added to PyTorch (https://docs.pytorch.org/docs/stable/optim.html#weight-averaging-swa-and-ema), and this repo is just a minimal implementation to go with the paper for reference, rather than something that should actually be used in practice.

@llbbl

llbbl commented Jun 30, 2025

Copy link
Copy Markdown
Author

Sure no problem.
I’m trying to get unit testing going for as many public projects as possible. The first PR is to set up testing. Additional PRs to be added as a follow-up with actual tests. I am tracking what PRs get merged.
For your project and others that are more of a reference implementation and not intended for actual use, adding tests would help other developers understand the code better by looking at the tests. Another form of documentation.

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.

2 participants