Testing Guide
Running Tests
Run all tests
Run unit tests
Run integration tests
Integration tests require real API keys:
cp tests/.env.example tests/.env
# Edit tests/.env and fill in real DEEPSEEK_API_KEY
pytest tests/ -v -m "integration"
Test Structure
tests/
├── test_schema.py # Data model tests
├── test_prompt_mgr.py # Prompt manager tests
├── test_llm_client.py # LLM client tests
├── test_expander.py # Core expander tests
└── test_integration.py # Integration tests
Writing Tests
Unit Tests
Unit tests use mock objects and don't require real API calls.
import pytest
from unittest.mock import AsyncMock, patch
from knowai_sse import Expander
@pytest.mark.asyncio
async def test_expand_success():
expander = Expander(api_key="test-key")
context = PlanetContext(theme="Test", values_map={})
mock_response = '{"instructions": []}'
with patch.object(expander.llm_client, 'chat_completion', new=AsyncMock(return_value=mock_response)):
result = await expander.expand(context)
assert len(result.instructions) == 0
Integration Tests
Integration tests use real API calls.
import os
from dotenv import load_dotenv
import pytest
from knowai_sse import Expander
load_dotenv()
@pytest.mark.integration
@pytest.mark.asyncio
async def test_real_api_call():
api_key = os.getenv("DEEPSEEK_API_KEY")
if not api_key:
pytest.skip("DEEPSEEK_API_KEY not set")
expander = Expander(api_key=api_key)
# Test real API call
Test Markers
@pytest.mark.asyncio: Mark async tests@pytest.mark.integration: Mark integration tests