Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
fix: test_sessions.py (#144)
Shawn Qiucba8035e028f
diff --git a/tests/test_session.py b/tests/test_session.pyindex b61e715f..2efe82a4 100644--- a/tests/test_session.py+++ b/tests/test_session.py@@ -18,34 +18,30 @@ class TestSessions:def setup_method(self):self.api_key = "random_api_key"self.event_type = 'test_event_type'- agentops.init(api_key=self.api_key, max_wait_time=5, auto_start_session=False)+ self.config = agentops.Configuration(api_key=self.api_key, max_wait_time=50)def test_session(self, mock_req):- # Arrange- agentops.start_session()+ agentops.start_session(config=self.config)- # Act+ agentops.record(ActionEvent(self.event_type))agentops.record(ActionEvent(self.event_type))- # Assert the session has been initiated and the id has been created on backend.+ # We should have 1 requests (session start).assert len(mock_req.request_history) == 1+ time.sleep(0.15)- # Act- agentops.record(ActionEvent(self.event_type))- time.sleep(0.1)-- # Assert an event has been added+ # We should have 2 requests (session and 2 events combined into 1)+ print(mock_req.last_request.json())assert len(mock_req.request_history) == 2assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_keyrequest_json = mock_req.last_request.json()assert request_json['events'][0]['event_type'] == self.event_type- # Actend_state = 'Success'agentops.end_session(end_state)- time.sleep(0.1)+ time.sleep(0.15)- # Since a session has ended, no more events should be recorded, but end_session should be called+ # We should have 3 requests (additional end session)assert len(mock_req.request_history) == 3assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_keyrequest_json = mock_req.last_request.json()@@ -55,13 +51,14 @@ class TestSessions:def test_tags(self, mock_req):# Arrangetags = ['GPT-4']- agentops.start_session(tags=tags)+ agentops.start_session(tags=tags, config=self.config)# Actagentops.record(ActionEvent(self.event_type))- time.sleep(0.1)+ time.sleep(0.15)# Assert 2 requests - 1 for session init, 1 for event+ print(mock_req.last_request.json())assert len(mock_req.request_history) == 2assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_keyrequest_json = mock_req.last_request.json()@@ -70,7 +67,7 @@ class TestSessions:# Actend_state = 'Success'agentops.end_session(end_state)- time.sleep(0.1)+ time.sleep(0.15)# Assert 3 requets, 1 for session init, 1 for event, 1 for end sessionassert len(mock_req.request_history) == 3