Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry#4

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

feat: Set up comprehensive Python testing infrastructure with Poetry#4
llbbl wants to merge 1 commit intoSkyworkAI:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jul 1, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the MoE++ Python project, providing developers with a ready-to-use testing environment powered by Poetry and pytest.

Changes Made

Package Management

  • Poetry configured as the primary package manager
  • Created pyproject.toml with project metadata and dependencies
  • Generated poetry.lock file for reproducible builds

Testing Dependencies

Added the following development dependencies:

  • pytest (^7.4.0) - Core testing framework
  • pytest-cov (^4.1.0) - Coverage reporting integration
  • pytest-mock (^3.11.1) - Mocking utilities for tests

Testing Configuration

pytest Configuration (pyproject.toml)

  • Minimum pytest version: 7.0
  • Automatic test discovery in tests/ directory
  • Coverage reporting with 80% threshold
  • Multiple output formats: terminal, HTML, and XML
  • Custom markers: unit, integration, slow
  • Strict mode enabled for better error detection

Coverage Configuration

  • Source directory: MoE++
  • Branch coverage enabled
  • Exclusions for test files and common patterns
  • HTML reports in htmlcov/ directory
  • XML reports for CI integration

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory management
  • mock_config - Sample configuration for testing
  • sample_data - Test data sets
  • env_vars - Environment variable management
  • reset_modules - Module state cleanup
  • mock_file_system - File system mocking
  • capture_logs - Log capture utilities

Development Commands

Both commands are available and execute pytest:

  • poetry run test - Run all tests
  • poetry run tests - Alternative command

Git Configuration

Updated .gitignore with:

  • Python-specific patterns
  • Testing artifacts (coverage reports, caches)
  • IDE files
  • Claude settings (.claude/*)
  • Note: poetry.lock is NOT ignored (best practice)

How to Use

  1. Install dependencies:

    poetry install
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific tests:

    poetry run pytest tests/unit/
    poetry run pytest -m unit
    poetry run pytest tests/test_specific.py::test_function
  4. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI tools

Validation

The setup includes test_setup_validation.py which verifies:

  • pytest is properly configured
  • All fixtures are working correctly
  • Coverage tracking is functional
  • Test markers are recognized
  • Mocking capabilities are available

All validation tests pass successfully, confirming the infrastructure is ready for use.

Notes

  • Coverage currently shows 0% as no actual tests for the MoE++ modules exist yet
  • The 80% coverage threshold will need actual module tests to pass
  • The infrastructure is designed to scale with the project's growth
  • All standard pytest plugins and options are available

- Initialize Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage thresholds, markers, and reporting
- Create testing directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common testing needs
- Update .gitignore with testing and Claude-specific entries
- Add validation tests to verify testing setup functionality
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