uncurled icon indicating copy to clipboard operation
uncurled copied to clipboard

feat: Set up Python testing infrastructure with Poetry

Open llbbl opened this issue 5 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the Python 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
  • Dependencies: Added testing dependencies 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

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Strict markers and configuration
    • Custom markers: unit, integration, slow
    • Verbose output with detailed failure reports
  • Coverage Configuration:

    • 80% coverage threshold requirement
    • HTML and XML report generation
    • Exclusion patterns for test files, virtual environments, and boilerplate code
    • Branch coverage tracking

Directory Structure

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

Testing Fixtures

Created comprehensive shared fixtures in conftest.py:

  • temp_dir - Temporary directory management
  • temp_file - Temporary file creation
  • mock_env_vars - Environment variable mocking
  • sample_markdown_file - Test data generation
  • sample_config - Configuration mocking
  • mock_file_system - File system structure mocking
  • capture_stdout - Output capturing

Development Commands

Configured Poetry scripts for running tests:

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

Additional Setup

  • Updated .gitignore with Python and testing patterns
  • Added Claude settings exclusion (.claude/*)
  • Created validation tests to verify the infrastructure

How to Use

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Install Dependencies:

    poetry install
    
  3. Run Tests:

    poetry run test
    # or
    poetry run tests
    
  4. Run Specific Test Categories:

    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 Reports:

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

Notes

  • The infrastructure is ready for immediate test development
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • All pytest options are available through the Poetry commands
  • The poetry.lock file is NOT gitignored and should be committed for reproducible builds
  • Validation tests are included to ensure the infrastructure works correctly

llbbl avatar Jun 28 '25 20:06 llbbl