This project has three levels of testing:
- Unit Tests - Fast, mocked tests that verify logic
- Integration Tests - Tests that call real APIs
- System Tests - End-to-end verification
pytestpytest -m "not integration and not slow"# Requires API keys to be set
pytest -m integrationpytest tests/test_classifier.py -vpytest --cov=src --cov-report=htmlIntegration tests make real API calls and require valid API keys.
-
Set environment variables:
# Linux/Mac export GROQ_API_KEY="your_groq_key_here" export HUGGING_FACE_API_KEY="your_hf_key_here" # Windows set GROQ_API_KEY=your_groq_key_here set HUGGING_FACE_API_KEY=your_hf_key_here
-
Or use
.envfile:echo "GROQ_API_KEY=your_key_here" >> .env echo "HUGGING_FACE_API_KEY=your_key_here" >> .env
# Run all integration tests
pytest tests/integration/ -m integration -v
# Run only API validation tests
pytest tests/integration/test_api_integration.py::TestAPIKeyValidation -v
# Run only model deprecation checks
pytest tests/integration/test_api_integration.py::TestModelDeprecation -vIntegration tests are automatically skipped if API keys are not configured:
# This will skip integration tests if no keys found
pytest tests/integration/tests/
├── conftest.py # Shared fixtures
├── test_chunker.py # ✅ HybridChunker unit tests (16 tests)
├── test_classifier.py # OllamaClassifier + GroqClassifier unit tests
├── test_transcriber.py # Transcriber unit tests
├── integration/
│ ├── test_api_integration.py # Real API tests
│ └── test_sample.py # Sample integration test
└── system/
└── test_system.py # System-level tests
@patch('src.classifier.Groq')
def test_groq_classifier_init(MockGroq):
"""Test GroqClassifier initialization with mocked API."""
classifier = GroqClassifier(api_key='test-key')
assert classifier.api_key == 'test-key'@pytest.mark.integration
def test_groq_real_api():
"""Test GroqClassifier with real API call."""
if not Config.GROQ_API_KEY:
pytest.skip("GROQ_API_KEY not configured")
classifier = GroqClassifier()
results = classifier.classify_segments([{'text': 'Test'}], [], [])
assert len(results) == 1- HybridChunker: ✅ Full coverage (16 tests) - VAD-based audio chunking
- OllamaClassifier: ✅ Full coverage (68 tests)
- GroqClassifier: ✅ Full coverage (13 tests)
- GroqTranscriber: ✅ Partial coverage (unit tests)
- Integration: ✅ API validation and deprecation checks
- ✅ chunker.py (P0-2): 16 tests - Initialization, chunking logic, VAD detection, edge cases
- ⏳ pipeline.py (P0-1): Not implemented - Main orchestration pipeline
pytest --cov=src --cov-report=html
open htmlcov/index.html # Linux/Mac
start htmlcov/index.html # Windows-
Unit Tests (
python-app.yml)- Runs on every push/PR
- Fast, no API keys required
- Must pass for merge
-
API Integration Tests (
api-integration-tests.yml)- Runs on push to main/feature branches
- Runs weekly (Sundays) to catch deprecations
- Requires secrets:
GROQ_API_KEY,HUGGING_FACE_API_KEY
-
Model Deprecation Check
- Automatically creates GitHub issue if models deprecated
- Labels:
bug,api,urgent
In GitHub repository settings:
- Go to Settings → Secrets and variables → Actions
- Add secrets:
GROQ_API_KEY: Your Groq API keyHUGGING_FACE_API_KEY: Your HuggingFace token
python test_api_keys.pyOutput:
================================================================================
API Key Validation Test Suite
================================================================================
================================================================================
Testing Groq API
================================================================================
✓ API Key found: gsk_abc123...
✓ Groq client initialized
✓ API Response: API test successful
✅ Groq API is working correctly!
================================================================================
Testing Hugging Face API
================================================================================
✓ API Key found: hf_xyz789...
✓ Authenticated as: your_username
✅ Hugging Face API is working correctly!
================================================================================
Test Summary
================================================================================
Groq API: ✅ PASS
Hugging Face API: ✅ PASS
🎉 All APIs are configured correctly!
-
Check API keys are set:
echo $GROQ_API_KEY echo $HUGGING_FACE_API_KEY
-
Verify keys are valid:
python test_api_keys.py
-
Check rate limits:
- Groq: Free tier has rate limits
- HuggingFace: ~1000 requests/day on free tier
If you see errors like:
Error code: 400 - {'error': {'message': 'The model `llama3-8b-8192` has been decommissioned...'}}
Fix:
- Check current models at console.groq.com/docs/models
- Update model names in:
src/classifier.py(GroqClassifier default model)src/transcriber.py(if needed)test_api_keys.py
- Update
CLOUD_INFERENCE_OPTIONS.mddocumentation - Run tests to verify
If mocks aren't being applied:
-
Check patch path:
@patch('src.classifier.Groq') # Correct: where it's imported # NOT @patch('groq.Groq') # Wrong: where it's defined
-
Verify import order:
@pytest.fixture(autouse=True) def patched_config(): with patch('src.classifier.Config') as MockConfig: yield MockConfig # Import AFTER patching from src.classifier import GroqClassifier
- Always mock in unit tests - Don't make real API calls
- Mark integration tests - Use
@pytest.mark.integration - Skip if no keys - Integration tests should skip gracefully
- Test error cases - Verify behavior on API errors
- Keep tests fast - Unit tests should run in < 1 second each
- Update tests with code - New features need new tests
@pytest.mark.slow # Test takes > 5 seconds
@pytest.mark.integration # Requires real APIs
@pytest.mark.system # System-level testRun specific markers:
pytest -m slow # Run only slow tests
pytest -m "not slow" # Skip slow tests
pytest -m integration # Run only integration tests# Run all tests
pytest
# Run fast tests only
pytest -m "not integration and not slow"
# Run with coverage
pytest --cov=src
# Run specific test
pytest tests/test_classifier.py::TestGroqClassifier::test_init_with_api_key -v
# Run and stop on first failure
pytest -x
# Run last failed tests
pytest --lf
# Verbose output
pytest -vv
# Show print statements
pytest -s
# Run integration tests
pytest -m integration