speechmetrics
speechmetrics copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
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.tomlwith Poetry configuration - Migrated all dependencies from
setup.pyto 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
- Automatic test discovery in
-
Coverage configuration:
- Source directory:
speechmetrics - Excluded: test files,
__init__.py, setup files - Detailed branch coverage reporting
- Source directory:
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.lockis intentionally NOT ignored (should be committed)
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install --with dev -
Run tests:
poetry run test # or poetry run tests -
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 -
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:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing scenarios
- Run tests locally before committing changes