Skip to content

Commit c8379d9

Browse files
author
Harmanpreet Kaur
committed
updated test_agentutils.py
1 parent b3f4305 commit c8379d9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/backend/tests/agents/test_agentutils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# pylint: disable=import-error, wrong-import-position, missing-module-docstring
2+
import asyncio
23
import json
34
import os
45
import sys
56
from unittest.mock import AsyncMock, MagicMock, patch
67
import pytest
78
from pydantic import ValidationError
89

9-
1010
# Environment and module setup
1111
sys.modules["azure.monitor.events.extension"] = MagicMock()
1212

@@ -22,9 +22,16 @@
2222
from src.backend.agents.agentutils import extract_and_update_transition_states # noqa: F401, C0413
2323
from src.backend.models.messages import Step # noqa: F401, C0413
2424

25+
@pytest.fixture(scope="function")
26+
async def reset_event_loop():
27+
"""Ensure a fresh event loop for each test."""
28+
yield
29+
loop = asyncio.get_event_loop()
30+
if not loop.is_closed():
31+
loop.close()
2532

2633
@pytest.mark.asyncio
27-
async def test_extract_and_update_transition_states_invalid_response():
34+
async def test_extract_and_update_transition_states_invalid_response(reset_event_loop):
2835
"""Test handling of invalid JSON response from model client."""
2936
session_id = "test_session"
3037
user_id = "test_user"
@@ -57,9 +64,8 @@ async def test_extract_and_update_transition_states_invalid_response():
5764

5865
cosmos_mock.update_step.assert_not_called()
5966

60-
6167
@pytest.mark.asyncio
62-
async def test_extract_and_update_transition_states_validation_error():
68+
async def test_extract_and_update_transition_states_validation_error(reset_event_loop):
6369
"""Test handling of a response missing required fields."""
6470
session_id = "test_session"
6571
user_id = "test_user"
@@ -95,7 +101,6 @@ async def test_extract_and_update_transition_states_validation_error():
95101

96102
cosmos_mock.update_step.assert_not_called()
97103

98-
99104
def test_step_initialization():
100105
"""Test Step initialization with valid data."""
101106
step = Step(
@@ -118,7 +123,6 @@ def test_step_initialization():
118123
assert step.status == "planned"
119124
assert step.human_approval_status == "requested"
120125

121-
122126
def test_step_missing_required_fields():
123127
"""Test Step initialization with missing required fields."""
124128
with pytest.raises(ValidationError):
@@ -128,4 +132,3 @@ def test_step_missing_required_fields():
128132
agent="test_agent",
129133
session_id="test_session",
130134
)
131-

0 commit comments

Comments
 (0)