Testing
AI4DRPM uses pytest as the primary testing framework with pytest-cov for code coverage measurement.
Test Organization
Tests are organized in the tests/ directory, mirroring the structure of the main application code:
tests/
├── unit/ # Unit tests (isolated components)
│ ├── test_services/
│ ├── test_models/
│ └── ...
├── integration/ # Integration tests (component interactions)
│ ├── test_api/
│ └── ...
└── e2e/ # End-to-end tests (full workflows)
Running Tests
Basic Test Execution
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ --cov=ai4drpm --cov-report=html --cov-report=term
# Run specific test file
pytest tests/unit/test_services/test_pipeline_service.py
# Run specific test function
pytest tests/unit/test_services/test_pipeline_service.py::test_pipeline_execution
Test Configuration
Tests use environment variables for configuration. Create a .env.test file or set variables directly:
# Example test configuration
DATABASE_URL=sqlite:///:memory:
TEST_MODE=true
Test Fixtures
Common fixtures are defined in tests/conftest.py:
db_session- Database session for each testtest_client- FastAPI test clientmock_llm- Mock LLM client for testingsample_legal_resource- Sample data for legal resources
Async Test Support
Use pytest-asyncio for async tests:
import pytest
@pytest.mark.asyncio
async def test_async_endpoint():
response = await client.get("/api/resources")
assert response.status_code == 200
Test Data
Sample test data is available in tests/fixtures/:
JSON files for API request/response payloads
Sample legal documents and provisions
Pipeline definitions
Coverage
Aim for 80%+ code coverage. Generate coverage reports:
# HTML report (open in browser)
pytest tests/ --cov=ai4drpm --cov-report=html
# Terminal summary
pytest tests/ --cov=ai4drpm --cov-report=term