Skip to content

Commit 48e4683

Browse files
committed
Add conftest.py to guard agent_framework imports in CI unit tests
In some CI environments (Linux Python 3.12) agent_framework loads but its top-level namespace is missing RawAgent/MCPStreamableHTTPTool due to a partial circular-import during pytest collection. The new conftest.py is loaded by pytest before test files in this directory tree are imported, and adds MagicMock stubs for any absent names so the module-level `from agent_framework import ...` in the production service succeeds.
1 parent 3dd83fe commit 48e4683

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
"""Conftest for Agent Framework tooling extension unit tests.
5+
6+
Ensures that ``agent_framework`` exports required by the production module are
7+
available in the test environment. In some CI configurations the package is
8+
importable but its internal initialisation leaves certain names absent from the
9+
top-level namespace (e.g. a partial circular-import during collection). We
10+
patch the stubs in at conftest *module load* time — which pytest guarantees
11+
happens before it imports any test file in this directory tree.
12+
"""
13+
14+
from __future__ import annotations
15+
16+
from unittest.mock import MagicMock
17+
18+
# fmt: off
19+
import agent_framework as _af # noqa: E402
20+
21+
_REQUIRED = ("RawAgent", "MCPStreamableHTTPTool", "Message", "HistoryProvider")
22+
for _name in _REQUIRED:
23+
if not hasattr(_af, _name):
24+
setattr(_af, _name, MagicMock(name=f"agent_framework.{_name}"))
25+
# fmt: on

0 commit comments

Comments
 (0)