crooked-dawn-90821
10/20/2025, 12:17 PMtall-airline-16756
10/20/2025, 12:17 PMtall-airline-16756
10/20/2025, 12:18 PMimport pytest
import pytest_asyncio
from livekit.agents import AgentSession
from livekit.plugins import openai
@pytest.mark.asyncio
async def test_session_creation():
async with openai.LLM(model="gpt-4o-mini") as llm:
async with AgentSession(llm=llm) as session:
await session.start(FunctionAgent())
result = await session.run(user_input="Hello")
assert result is not None
• Mock Testing: For CI, using fake or mock components is a great way to keep tests fast and reliable without depending on external services. Here’s an example:
def create_mock_session():
return AgentSession(
llm=FakeLLM(),
stt=FakeSTT(),
tts=FakeTTS()
)
• Reusable Fixtures: You can also use pytest fixtures to make your test setup consistent and easy to manage:
@pytest_asyncio.fixture
async def agent_session():
async with AgentSession(llm=FakeLLM()) as session:
yield session
For CI environments, I’d recommend leaning on the mock component approach to keep things speedy, independent, and predictable. If you’d like, I’m here to help you set up specific test scenarios or assist with integrating these tests into your CI pipeline. Just let me know!
Sources: basics/repeater.py | tests/test_evals.py | Testing and evaluation | LiveKit Docs | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki