Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 27, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the ML Interpretability Papers project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Initialized Poetry as the package manager with pyproject.toml configuration
  • Added project metadata and package configuration for the sbin module

Testing Dependencies

Added the following development dependencies:

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

Testing Configuration

  • Configured pytest in pyproject.toml with:
    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, and slow
    • Strict mode for markers and configuration
  • Added .coveragerc for detailed coverage configuration:
    • 80% coverage threshold (commented out for initial setup)
    • HTML and XML report generation
    • Exclusion patterns for non-testable code

Directory Structure

Created organized testing structure:

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

Fixtures and Configuration

Added comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory for testing
  • sample_cache_data - Sample data for cache testing
  • sample_cache_file - Test cache file creation
  • sample_readme_template - Test template file
  • mock_http_response - HTTP response mocking helper
  • mock_env_vars - Environment variable management
  • isolated_filesystem - Isolated test environment

Development Commands

Configured Poetry scripts for consistent test execution:

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)

Additional Setup

  • Updated .gitignore with comprehensive Python, testing, and Claude-specific entries
  • Added sbin/__init__.py to make it a proper Python package
  • Created validation tests to verify the infrastructure works correctly

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    # Run all tests
    poetry run test
    
    # Run with coverage
    poetry run pytest --cov=sbin --cov-report=html
    
    # Run specific test markers
    poetry run pytest -m unit
    poetry run pytest -m integration
  3. Write new tests:

    • Unit tests go in tests/unit/
    • Integration tests go in tests/integration/
    • Use fixtures from conftest.py for common test needs
    • Mark tests appropriately with @pytest.mark.unit, etc.

Notes

  • The coverage threshold is currently commented out in .coveragerc since no actual code tests exist yet
  • The validation tests confirm that all testing infrastructure is properly installed and configured
  • Poetry lock file is tracked in git for reproducible environments
  • All pytest options and plugins are available for use

- Initialize Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with markers (unit, integration, slow)
- Create test directory structure with conftest.py and fixtures
- Add comprehensive .gitignore including testing and Claude artifacts
- Set up Poetry scripts for test execution (test/tests commands)
- 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