Comprehensive test suite for the multi-agent system.
tests/
├── unit/ # Fast, isolated tests (no external dependencies)
├── integration/ # Tests with Databricks services
├── e2e/ # End-to-end system tests
├── conftest.py # Shared fixtures
└── README.md # This file
# Run all tests
pytest
# Run unit tests only (fast, ~1 minute)
pytest tests/unit/
# Run integration tests (requires Databricks, ~5-10 minutes)
pytest tests/integration/
# Run end-to-end tests (full system, ~10-15 minutes)
pytest tests/e2e/
# Run with coverage
pytest --cov=src.multi_agent tests/
# Run specific test file
pytest tests/unit/test_config.py -v
# Run specific test function
pytest tests/unit/test_agents.py::test_supervisor_agent -v
Tests are automatically marked based on location:
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Run only e2e tests
pytest -m e2e
# Exclude slow tests
pytest -m "not slow"
tests/unit/)Purpose: Test individual components in isolation
Characteristics:
Examples:
test_config.py: Configuration loadingtest_agents.py: Individual agent logictest_tools.py: Tool functionstest_utils.py: Utility functionsRun frequently: After every code change
tests/integration/)Purpose: Test integration with Databricks services
Characteristics:
Examples:
test_vector_search_detailed.py: Vector search integrationtest_sql_validation_agent.py: SQL validation with real warehousetest_genie_routing_and_SQL_synthesis_agent.py: Genie integrationtest_notebooks_runner.py: Notebook executionRun before: Committing significant changes
tests/e2e/)Purpose: Test complete multi-agent system
Characteristics:
Examples:
test_multi_agent_system.py: Complete agent workflowsRun before: Deploying to production
Uses .env file with test values:
# .env
TEST_MODE=1
CATALOG_NAME=test_catalog
SCHEMA_NAME=test_schema
# ... other test values
If you don’t have Databricks access:
# Skip integration tests
SKIP_INTEGRATION=1 pytest
# Or skip via marker
pytest -m "not integration"
# tests/unit/test_config.py
import pytest
from config import get_config
def test_config_loads():
"""Test configuration loads successfully."""
config = get_config()
assert config.unity_catalog.catalog_name is not None
assert config.llm.endpoint_name is not None
def test_config_validation():
"""Test configuration validation."""
config = get_config()
config.validate() # Should not raise
# tests/integration/test_vector_search.py
import pytest
@pytest.mark.integration
def test_vector_search(test_config, skip_integration):
"""Test vector search with real endpoint."""
if skip_integration:
pytest.skip("Integration tests disabled")
from multi_agent.tools.vector_search import search_genie_spaces
results = search_genie_spaces("patient demographics")
assert len(results) > 0
assert "space_id" in results[0]
# tests/e2e/test_multi_agent_system.py
import pytest
@pytest.mark.e2e
@pytest.mark.slow
def test_complete_query_workflow(test_config, sample_query):
"""Test complete agent workflow end-to-end."""
from multi_agent.core.graph import create_agent_graph
agent = create_agent_graph(test_config)
response = agent.invoke({"input": [{"role": "user", "content": sample_query}]})
assert response is not None
assert "final_response" in response
assert len(response["final_response"]) > 0
Shared fixtures in conftest.py:
test_config: Test configuration from .envsample_query: Sample query stringsample_conversation: Sample conversation dictsample_state: Sample agent statemock_genie_response: Mocked Genie responsemock_vector_search_results: Mocked vector search resultsTests run automatically on:
See .github/workflows/ci.yml for CI configuration.
Maintain test coverage above 80%:
# Generate coverage report
pytest --cov=src.multi_agent --cov-report=html tests/
# View report
open htmlcov/index.html
Problem: ModuleNotFoundError: No module named 'multi_agent'
Solution:
# Make sure you're in repo root
cd /path/to/KUMC_POC_hlsfieldtemp
# Install in development mode
pip install -e .
Problem: Databricks connection errors
Solution:
.env file has correct credentialsSKIP_INTEGRATION=1 to skipProblem: Tests taking too long
Solution:
# Run only fast unit tests
pytest tests/unit/
# Skip slow tests
pytest -m "not slow"
# Run in parallel
pip install pytest-xdist
pytest -n auto
@pytest.mark.slowtest_<feature>_<scenario> patternRun tests often! They’re your safety net. 🛡️