Skip to content

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

Open
llbbl wants to merge 1 commit into
aliutkus:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#44
llbbl wants to merge 1 commit into
aliutkus:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 20, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the speechmetrics project, migrating from setup.py to Poetry for modern dependency management and adding pytest with coverage reporting.

Changes Made

Package Management Migration

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from setup.py to Poetry format
  • Added development dependencies group for testing tools

Testing Setup

  • Testing Framework: pytest (^7.4.0)
  • Coverage Tool: pytest-cov (^4.1.0)
  • Mocking Library: pytest-mock (^3.11.0)

Configuration

  • pytest configuration in pyproject.toml:

    • Automatic test discovery in tests/ directory
    • Coverage reporting with 80% threshold
    • Multiple output formats (terminal, HTML, XML)
    • Custom markers: unit, integration, slow
    • Strict marker enforcement
  • Coverage configuration:

    • Source directory: speechmetrics
    • Excluded: test files, __init__.py, setup files
    • Detailed branch coverage reporting

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • sample_audio_data: Generate test audio arrays
  • sample_rate: Standard 16kHz sample rate
  • mock_config: Configuration dictionary for testing
  • example_wav_file: Create temporary WAV files
  • reset_environment: Environment variable isolation
  • mock_tensorflow: TensorFlow mocking for faster tests
  • noisy_audio_pair: Clean/noisy audio pair generation

Poetry Scripts

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

.gitignore Updates

  • Added testing artifacts: .pytest_cache/, .coverage, htmlcov/, coverage.xml
  • Added Claude settings: .claude/*
  • Added IDE files and virtual environments
  • Note: poetry.lock is intentionally NOT ignored (should be committed)

How to Use

  1. Install Poetry (if not already installed):

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

    poetry install --with dev
  3. Run tests:

    poetry run test
    # or
    poetry run tests
  4. Run specific test types:

    poetry run pytest -m unit        # Unit tests only
    poetry run pytest -m integration # Integration tests only
    poetry run pytest -m "not slow"  # Exclude slow tests
  5. View coverage report:

    # Terminal report is shown automatically
    # HTML report available at: htmlcov/index.html

Notes

  • The infrastructure is ready for developers to start writing tests immediately
  • All pytest standard options are available through the Poetry scripts
  • Coverage threshold is set to 80% - builds will fail if coverage drops below this
  • Validation tests are included to verify the setup works correctly
  • Git dependencies in pyproject.toml may need adjustment based on the specific versions required

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests locally before committing changes

- Migrate from setup.py to Poetry package management in pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure with unit/integration separation
- Add comprehensive shared fixtures in conftest.py
- Configure custom pytest markers (unit, integration, slow)
- Update .gitignore with testing and Claude-specific entries
- Add Poetry script commands for running tests
- Create 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