able-jackal-19719
10/24/2025, 1:03 PMtall-airline-16756
10/24/2025, 1:03 PMtall-airline-16756
10/24/2025, 1:03 PMable-jackal-19719
10/24/2025, 1:30 PMtall-airline-16756
10/24/2025, 1:31 PMunittest module or the popular third-party pytest framework. Here's a simple example using unittest to guide you:
import unittest
class Calculator:
def add(self, a, b):
return a + b
def divide(self, a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
class TestCalculator(unittest.TestCase):
def setUp(self):
self.calculator = Calculator()
def test_add(self):
self.assertEqual(self.calculator.add(2, 3), 5)
def test_divide(self):
self.assertEqual(self.calculator.divide(10, 2), 5.0)
def test_divide_by_zero(self):
with self.assertRaises(ValueError):
self.calculator.divide(10, 0)
if __name__ == '__main__':
unittest.main()
If you prefer something a bit more flexible and concise, pytest is a wonderful option. Here's how you could write similar tests with it:
import pytest
class Calculator:
def add(self, a, b):
return a + b
def divide(self, a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def test_add():
calculator = Calculator()
assert calculator.add(2, 3) == 5
def test_divide():
calculator = Calculator()
assert calculator.divide(10, 2) == 5.0
def test_divide_by_zero():
calculator = Calculator()
with pytest.raises(ValueError):
calculator.divide(10, 0)
Please feel free to reach out if you'd like me to walk you through more examples or help with anything else. I'm here to support you!
Sources: Testing and evaluation | LiveKit Docs | complex-agents/testing/agent_test.py | .github/workflows/tests.ymlable-jackal-19719
10/24/2025, 1:33 PMtall-airline-16756
10/24/2025, 1:34 PMpytest framework along with pytest-asyncio. Here’s a simple example to get you started with testing an agent's behavior:
import pytest
from livekit.agents import MockedLLM, TestAgentSession
from your_agent_module import entrypoint # Replace with your agent's entrypoint
@pytest.mark.asyncio
async def test_greeting():
session = TestAgentSession(entrypoint_fnc=entrypoint)
events = await session.say("Hello")
# Assert the agent responded with a greeting
assert any("hello" in evt.text.lower() or "hi " in evt.text.lower()
for evt in events if evt.type == "agent_speech")
Here are a few helpful tips for testing your LiveKit agents:
• Use TestAgentSession to simulate conversations with your agent.
• Mock external services such as LLMs with MockedLLM to make your tests faster and more reliable.
• Try testing multi-turn interactions by chaining session.say() calls to see how your agent handles ongoing conversations.
• Check tool usage and error handling by using mock_tools to cover those scenarios.
If you’d like, I’m here to provide more examples or walk you through any part of this. Just let me know!
Sources: Testing and evaluation | LiveKit Docs | tests/__init__.py | complex-agents/drive-thru/test_agent.py | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik...