I’m using the python SDK, how can I test in my CI ...
# ask-ai
c
I’m using the python SDK, how can I test in my CI that the AgentSession can be created properly. What’s a common test setup?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you test AgentSession creation in CI using the Python SDK, here are some friendly approaches you can try out: • Basic Testing: You can use real components to test the session lifecycle. For example:
Copy code
import 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:
Copy code
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:
Copy code
@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