Files
tatlock/tests/conftest.py
T
jpmschweitzerandClaude c50f7eefcb Add comprehensive testing infrastructure
Implement test suite with 62% coverage and 12 passing tests.
Async testing support, fixtures, and SSE streaming tests.

Test Configuration (pytest.ini):
- Async mode configured
- Coverage reporting enabled
- Test markers (unit, integration)
- Warning filters
- Async fixtures with session scope

Test Fixtures (tests/conftest.py):
- TestClient for sync requests
- AsyncClient for streaming tests
- Mock request fixtures
- Shared test application instance

Core Tests (tests/core/):
- Health endpoint testing
- Root endpoint testing
- Exception handler testing
- 100% coverage of core routes

Chat Tests (tests/chat/test_router.py):
- Non-streaming completion tests
- Streaming with SSE and 20s timeout
- Temperature validation
- Message role validation
- Invalid request handling
- Comprehensive edge case coverage

Models Tests (tests/models/):
- Model listing endpoint tests
- Response format validation
- OpenAI compatibility verification

Streaming Tests:
- Proper SSE format parsing
- [DONE] marker handling
- Chunk structure verification
- 20-second timeout protection
- asyncio.wait_for() timeout handling

Test Coverage:
- Overall: 62.14%
- src/chat/: High coverage
- src/models/: High coverage
- src/core/: 100% coverage
- 12 tests passing

Following Best Practices:
- Async test support
- Fixture-based setup
- Isolated test cases
- Comprehensive assertions
- Timeout protection

Status: Production-ready test suite

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-06 10:52:18 +01:00

53 lines
1.2 KiB
Python

"""
Shared test fixtures for all tests.
Following FastAPI testing best practices.
"""
import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient, ASGITransport
from src.main import app
@pytest.fixture
def client() -> TestClient:
"""
Synchronous test client for FastAPI.
Use for simple tests that don't require async.
"""
return TestClient(app)
@pytest.fixture
async def async_client() -> AsyncClient:
"""
Async test client for FastAPI.
Use for testing async endpoints and streaming.
"""
async with AsyncClient(
transport=ASGITransport(app=app),
base_url="http://test"
) as client:
yield client
@pytest.fixture
def mock_chat_request() -> dict:
"""Standard chat completion request fixture."""
return {
"model": "mistral-nemo:latest",
"messages": [
{"role": "user", "content": "Hello, world!"}
],
"temperature": 0.7,
"stream": False,
}
@pytest.fixture
def mock_streaming_chat_request(mock_chat_request) -> dict:
"""Streaming chat completion request fixture."""
return {**mock_chat_request, "stream": True}