Overview
The test suite covers:- RAG retrieval and answer generation
- Document ingestion pipelines
- ML model training and prediction
- API endpoints and services
- Structured outputs and verification
Prerequisites
- Python 3.12+ installed
- Dependencies installed via
uv sync - Test files located in
tests/directory
Running Tests
Full Test Suite (Quiet Mode)
Run all tests with minimal output:Verbose Mode with Print Statements
Run tests with detailed output and capture print statements:-s: Show print statements and logging output-v: Verbose mode (show test names)
Run Specific Test File
Execute tests from a single file:Run Specific Test Function
Execute a single test:Test Structure
Tests are organized in thetests/ directory:
Mocking External Services
All tests mock external API calls to ensure offline execution:Mocked Services
- OpenAI API: LLM calls and embeddings
- Chroma: Vector database operations
- Unstructured API: Document parsing
Test Coverage
RAG Retrieval Tests
Validate search and answer generation:Ingestion Tests
Validate document processing:ML Training Tests
Validate model training:API Tests
Validate HTTP endpoints:Running Tests in CI
The project includes a GitHub Actions workflow (.github/workflows/ci.yml) that:
- Sets up Python environment
- Installs dependencies
- Runs full test suite
- Reports test results
Test Fixtures
Common fixtures are defined inconftest.py:
Test Output and Reports
Pytest generates detailed output:Success Output
Failure Output
Best Practices
Running Tests During Development
-
Before committing: Run full test suite
-
During feature development: Run relevant test file
-
Debugging failures: Use verbose mode with prints
Writing New Tests
When adding new functionality:- Create test file in
tests/directory - Import necessary mocks from
conftest.py - Write test functions with
test_prefix - Mock all external API calls
- Assert expected behavior
Troubleshooting
ModuleNotFoundError: No module named 'src'
ModuleNotFoundError: No module named 'src'
Ensure you’re running pytest from the project root directory and dependencies are installed:
Tests fail with API key errors
Tests fail with API key errors
Tests should NOT require real API keys. If you see this error, mocking may be incomplete. Check that:
- External services are properly mocked
- Environment variables are not being accessed in test code
Tests pass locally but fail in CI
Tests pass locally but fail in CI
Common causes:
- Missing test dependencies in CI environment
- Path differences between local and CI
- Race conditions in parallel test execution
ImportError: cannot import name 'X' from 'src.module'
ImportError: cannot import name 'X' from 'src.module'
This usually indicates:
- Circular import in source code
- Missing
__init__.pyfiles - Incorrect import paths