drum-machine icon indicating copy to clipboard operation
drum-machine copied to clipboard

feat: Set up complete Python testing infrastructure with Poetry

Open llbbl opened this issue 3 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the drum machine project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Set up Poetry as the primary package manager with pyproject.toml
  • Migrated dependencies from requirements.txt to Poetry configuration
  • Added development dependencies: pytest, pytest-cov, pytest-mock

Testing Configuration

  • Comprehensive pytest configuration in pyproject.toml including:
    • Test discovery patterns for different test types
    • Coverage settings with 80% threshold requirement
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow for test categorization
    • Strict configuration to catch issues early

Directory Structure

  • Created testing directories:
    • tests/ - Main testing directory
    • tests/unit/ - Unit tests
    • tests/integration/ - Integration tests
    • All directories include __init__.py files

Shared Test Utilities

  • Comprehensive fixtures in tests/conftest.py:
    • temp_dir, temp_file - Temporary file system utilities
    • mock_config - Mock configuration objects
    • mock_pygame, mock_mido - Audio library mocks
    • mock_gtk, mock_gio - GTK/GIO component mocks
    • sample_sound_files, sample_preset_file - Test data generators
    • drum_pattern_data - Sample drum patterns
    • isolate_file_system - File system isolation
    • capturing_logger - Log capture for testing

Development Tools

  • Poetry script commands:
    • poetry run test - Run all tests
    • poetry run tests - Alternative test command
  • Updated .gitignore to exclude testing artifacts and include Claude Code settings

Validation

  • Infrastructure validation tests in tests/test_infrastructure.py
  • All fixtures and markers are tested and working
  • Coverage reporting generates properly (HTML, XML, terminal)

How to Run Tests

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run tests with verbose output
poetry run pytest -v

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run tests without coverage (for development)
poetry run pytest --no-cov

# Generate coverage reports
poetry run pytest --cov-report=html

Coverage Reports

  • HTML coverage report: Generated in htmlcov/ directory
  • XML coverage report: Generated as coverage.xml
  • Terminal coverage: Shows missing lines in terminal output
  • Coverage threshold: Set to 80% (configurable in pyproject.toml)

Testing Best Practices Enabled

  • Isolated test environment with temporary directories
  • Comprehensive mocking for external dependencies (GTK, pygame, mido)
  • Fixture-based test data for consistent testing
  • Multiple test categories with custom markers
  • Coverage tracking with reasonable thresholds
  • Strict pytest configuration to catch configuration issues

Notes

  • The poetry.lock file is included in version control (not in .gitignore) for reproducible builds
  • All testing dependencies are in the [tool.poetry.group.dev.dependencies] section
  • The testing infrastructure is ready for immediate use - developers can start writing tests right away
  • Validation tests confirm that all fixtures and configuration work correctly

🤖 Generated with Claude Code

llbbl avatar Sep 03 '25 14:09 llbbl