This document provides comprehensive information about testing the Cleanvoice Python SDK.
Fast, isolated tests that don't require external dependencies or API calls.
# Run all unit tests
pytest tests/ -m "not integration"
# Run with coverage
pytest tests/ -m "not integration" --cov=cleanvoice --cov-report=term-missing
# Run specific test files
pytest tests/test_basic.py tests/test_client.pyTests that interact with real Cleanvoice API endpoints. These require:
- Valid API key
- Internet connection
- May consume API credits
# Set up environment
export CLEANVOICE_API_KEY=your-api-key-here
# Run integration tests
pytest tests/test_integration.py -m integration
# Or use the helper script
python run_integration_tests.pyCLEANVOICE_API_KEY: Your Cleanvoice API key
CLEANVOICE_BASE_URL: Custom API base URL (default: https://api.cleanvoice.ai/v2)CLEANVOICE_TEST_AUDIO_URL: Custom test audio file URL
pytest tests/ -m "not integration" --tb=short# Set API key first
export CLEANVOICE_API_KEY=your-key-here
# Run all tests
pytest tests/ --tb=short# Quick integration tests (fast)
python run_integration_tests.py quick
# All integration tests (may take several minutes)
python run_integration_tests.py all
# Slow integration tests only
python run_integration_tests.py slowpytest tests/ -m "not integration" --cov=cleanvoice --cov-report=html
# Open htmlcov/index.html to view coverage reportTests are marked with pytest markers to control execution:
@pytest.mark.integration: Requires real API, may consume credits@pytest.mark.slow: Long-running tests (>30 seconds)@pytest.mark.unit: Fast unit tests (default)
# Only integration tests
pytest -m integration
# Only slow tests
pytest -m slow
# Integration but not slow
pytest -m "integration and not slow"
# Everything except integration
pytest -m "not integration"tests/
├── test_basic.py # Basic SDK functionality
├── test_client.py # API client HTTP interactions
├── test_process_method.py # Process method comprehensive tests
├── test_error_handling.py # Error scenarios and edge cases
├── test_file_handler.py # File validation utilities
├── test_file_handler_advanced.py # Advanced file handling (incomplete)
└── test_integration.py # Real API integration tests
- Valid API key authentication
- Invalid API key handling
- Different base URL configurations
- Create edit jobs
- Retrieve edit status
- Basic audio processing
- Full processing with polling
- Transcription and summarization
- Progress callback functionality
- Invalid file URLs
- Server errors and rate limiting
- Network timeout handling
- Concurrent API calls
- Polling timeout behavior
- Large configuration objects
For CI/CD pipelines, use unit tests by default:
# GitHub Actions example
- name: Run tests
run: pytest tests/ -m "not integration" --cov=cleanvoice
# Only run integration tests if API key is available
- name: Run integration tests
if: ${{ secrets.CLEANVOICE_API_KEY }}
env:
CLEANVOICE_API_KEY: ${{ secrets.CLEANVOICE_API_KEY }}
run: pytest tests/test_integration.py -m "integration and not slow"Import Errors
# Install SDK in development mode
pip install -e .Integration Test Authentication Failures
# Check API key
echo $CLEANVOICE_API_KEY
# Test authentication directly
python -c "
from cleanvoice import Cleanvoice
cv = Cleanvoice({'api_key': '$CLEANVOICE_API_KEY'})
print(cv.check_auth())
"Network/Timeout Issues
- Check internet connection
- Verify API endpoint is accessible
- Try increasing timeout values
Rate Limiting
- Reduce concurrent test execution
- Add delays between API calls
- Use test API endpoint if available
The integration tests use a public test audio file by default. You can provide your own:
export CLEANVOICE_TEST_AUDIO_URL=https://your-domain.com/test-audio.mp3Requirements for test audio files:
- Publicly accessible URL
- Valid audio format (mp3, wav, etc.)
- Small file size (< 1MB recommended for tests)
- Short duration (< 30 seconds recommended)
- Run unit tests frequently during development
- Run integration tests before releases
- Use appropriate test markers to control execution
- Mock external dependencies in unit tests
- Keep integration tests focused and fast when possible
- Document test requirements clearly
- Use environment variables for configuration
- Handle test cleanup properly (API resources)
- Unit Tests: > 90% line coverage
- Integration Tests: Cover all major user workflows
- Critical Paths: 100% coverage (authentication, processing, errors)
Current coverage: 73% overall, 100% on core modules.