Skip to content

Commit b3c2ef4

Browse files
Testcases
1 parent 2feb981 commit b3c2ef4

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/backend/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,4 +769,5 @@ async def get_agent_tools():
769769
if __name__ == "__main__":
770770
import uvicorn
771771

772-
uvicorn.run("app:app", host="127.0.0.1", port=8000, reload=True)
772+
uvicorn.run("app:app", host="127.0.0.1", port=8000, reload=True)
773+

src/backend/tests/agents/test_human.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,51 @@
88
from unittest.mock import AsyncMock, MagicMock, patch
99
import pytest
1010

11-
# Set environment variables before any imports to avoid runtime errors
12-
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
13-
os.environ["COSMOSDB_KEY"] = "mock-key"
14-
os.environ["COSMOSDB_DATABASE"] = "mock-database"
15-
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
16-
os.environ["APPLICATIONINSIGHTS_INSTRUMENTATION_KEY"] = "mock-instrumentation-key"
17-
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
18-
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
19-
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
11+
# Function to set environment variables
12+
def setup_environment_variables():
13+
"""Set environment variables required for the tests."""
14+
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
15+
os.environ["COSMOSDB_KEY"] = "mock-key"
16+
os.environ["COSMOSDB_DATABASE"] = "mock-database"
17+
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
18+
os.environ["APPLICATIONINSIGHTS_INSTRUMENTATION_KEY"] = "mock-instrumentation-key"
19+
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
20+
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
21+
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
22+
23+
# Call the function to set environment variables
24+
setup_environment_variables()
2025

2126
# Mock Azure and event_utils dependencies globally
2227
sys.modules["azure.monitor.events.extension"] = MagicMock()
2328
sys.modules["src.backend.event_utils"] = MagicMock()
2429

25-
# Project-specific imports
30+
# Project-specific imports (must come after environment setup)
2631
from autogen_core.base import AgentInstantiationContext, AgentRuntime
2732
from src.backend.agents.human import HumanAgent
2833
from src.backend.models.messages import HumanFeedback, Step, StepStatus, BAgentType
2934

3035

36+
@pytest.fixture(autouse=True)
37+
def ensure_env_variables(monkeypatch):
38+
"""
39+
Fixture to ensure environment variables are set for all tests.
40+
This overrides any modifications made by individual tests.
41+
"""
42+
env_vars = {
43+
"COSMOSDB_ENDPOINT": "https://mock-endpoint",
44+
"COSMOSDB_KEY": "mock-key",
45+
"COSMOSDB_DATABASE": "mock-database",
46+
"COSMOSDB_CONTAINER": "mock-container",
47+
"APPLICATIONINSIGHTS_INSTRUMENTATION_KEY": "mock-instrumentation-key",
48+
"AZURE_OPENAI_DEPLOYMENT_NAME": "mock-deployment-name",
49+
"AZURE_OPENAI_API_VERSION": "2023-01-01",
50+
"AZURE_OPENAI_ENDPOINT": "https://mock-openai-endpoint",
51+
}
52+
for key, value in env_vars.items():
53+
monkeypatch.setenv(key, value)
54+
55+
3156
@pytest.fixture
3257
def setup_agent():
3358
"""

src/backend/tests/agents/test_product.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
evaluate_product_performance,
4242
)
4343

44+
4445
# Parameterized tests for repetitive cases
4546
@pytest.mark.asyncio
4647
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)