Testing
MoneyPrinter usespytest for backend testing with isolated database fixtures.
Quick Start
Install Test Dependencies
Install development dependencies including pytest:pyproject.toml
Run All Tests
Test Structure
Test Files
| File | Description |
|---|---|
tests/test_api_jobs.py | API endpoints for job queue, status, events, and cancellation |
tests/test_api_misc.py | Model listing fallback and song upload behavior |
tests/test_repository.py | Database operations (create, claim, cancel, completion) |
tests/test_worker.py | Worker loop behavior (success, failure, cancellation, empty queue) |
tests/test_utils.py | Filesystem cleanup, song selection, ImageMagick resolution |
tests/conftest.py | Shared fixtures (isolated database per test) |
Test Fixtures
Tests use an isolated SQLite database:tests/conftest.py
Running Tests
Run Specific Test File
Run Single Test
Run Test Class
Run with Verbose Output
Run with Coverage
htmlcov/index.html to view coverage report.
Example Tests
Repository Tests
Test job creation and event logging:tests/test_repository.py
Worker Tests
Test worker processes jobs:tests/test_worker.py
API Tests
Test API endpoints:tests/test_api_jobs.py
Test Coverage
Current test scope:API Coverage
- ✅ Job creation (
POST /api/generate) - ✅ Job status retrieval (
GET /api/jobs/:id) - ✅ Event streaming (
GET /api/jobs/:id/events) - ✅ Job cancellation (
POST /api/jobs/:id/cancel) - ✅ Model listing with fallback (
GET /api/models) - ✅ Song upload (
POST /api/upload-songs)
Repository Coverage
- ✅ Job creation with events
- ✅ Job claiming with Postgres/SQLite
- ✅ Event appending
- ✅ Job completion
- ✅ Job failure
- ✅ Job cancellation (queued and running)
Worker Coverage
- ✅ Process job success
- ✅ Process job failure
- ✅ Process job cancellation
- ✅ Handle empty queue
- ✅ Clean temp directories
Utility Coverage
- ✅ Directory cleanup
- ✅ Random song selection
- ✅ ImageMagick binary resolution
- ✅ Environment variable validation
Writing New Tests
Test Template
tests/test_example.py
Mocking External Services
Mock Ollama API calls:Testing Error Conditions
Continuous Integration
GitHub Actions Example
.github/workflows/test.yml
Test Best Practices
Isolation
Each test uses a fresh database. No shared state.
Speed
Use in-memory SQLite for fast test execution.
Mocking
Mock external services (Ollama, Pexels, TikTok) to avoid network calls.
Coverage
Aim for >80% code coverage on core modules.
Troubleshooting
Import errors when running tests
Import errors when running tests
Error:Solution:Ensure you’re running tests with Not:
uv run:Database conflicts between tests
Database conflicts between tests
Symptom: Tests pass individually but fail when run together.Solution: Ensure each test uses
db_session fixture:Slow tests
Slow tests
Causes:
- Not using in-memory database
- Not mocking external APIs
- Running actual video generation
- Use
:memory:SQLite for tests - Mock
run_generation_pipeline - Avoid real API calls
Next Steps
Contributing
Contribute to MoneyPrinter
Architecture
Understand the system design
Troubleshooting
Common issues and solutions
Development Guide
Development workflow and standards