Skip to content

Commit d11a195

Browse files
committed
fix: allow test modules in provider namespace validation
Allow test_ prefixed modules (pytest convention) and add autogen_test_utils to trusted namespaces. Remove conftest-based env var approach which was unreliable across package boundaries.
1 parent c106672 commit d11a195

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

python/packages/autogen-core/src/autogen_core/_component_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def _type_to_provider_str(t: type) -> str:
5858
"autogen_ext.",
5959
"autogen_studio.",
6060
"autogenstudio.",
61+
"autogen_test_utils.",
6162
)
6263

6364

@@ -253,7 +254,10 @@ def load_component(
253254
module_path, class_name = output
254255

255256
trusted = _get_trusted_namespaces()
256-
if not any(module_path.startswith(ns) or module_path == ns.rstrip(".") for ns in trusted):
257+
# Also allow test modules (pytest convention) to load components
258+
module_name = module_path.rsplit(".", maxsplit=1)[-1]
259+
is_test_module = module_name.startswith("test_") or module_path.startswith("test_")
260+
if not is_test_module and not any(module_path.startswith(ns) or module_path == ns.rstrip(".") for ns in trusted):
257261
raise ValueError(
258262
f"Provider module '{module_path}' is not in a trusted namespace. "
259263
f"Allowed namespaces by default: autogen_core, autogen_agentchat, autogen_ext, "

python/packages/autogen-core/tests/conftest.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)