drum-machine
drum-machine copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
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.txtto Poetry configuration - Added development dependencies: pytest, pytest-cov, pytest-mock
Testing Configuration
- Comprehensive pytest configuration in
pyproject.tomlincluding:- Test discovery patterns for different test types
- Coverage settings with 80% threshold requirement
- HTML and XML coverage report generation
- Custom markers:
unit,integration,slowfor test categorization - Strict configuration to catch issues early
Directory Structure
- Created testing directories:
tests/- Main testing directorytests/unit/- Unit teststests/integration/- Integration tests- All directories include
__init__.pyfiles
Shared Test Utilities
- Comprehensive fixtures in
tests/conftest.py:temp_dir,temp_file- Temporary file system utilitiesmock_config- Mock configuration objectsmock_pygame,mock_mido- Audio library mocksmock_gtk,mock_gio- GTK/GIO component mockssample_sound_files,sample_preset_file- Test data generatorsdrum_pattern_data- Sample drum patternsisolate_file_system- File system isolationcapturing_logger- Log capture for testing
Development Tools
- Poetry script commands:
poetry run test- Run all testspoetry 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.lockfile 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