From 67d3974ace3716b6ee07a38a97b0ae871dfc9138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=90=E8=97=A4=E5=84=AA=E4=B8=80?= Date: Mon, 11 Aug 2025 11:01:59 +0900 Subject: [PATCH] Fix ToolNode Mock compatibility: Use real functions - Create actual functions instead of pure Mock objects - Functions have proper __name__ and __qualname__ attributes - Wrapped in Mock for test assertions - Fixes TypeError: Mock is not a module/class/method/function --- tests/unit/graph/mock_toolkit_fix.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/unit/graph/mock_toolkit_fix.py b/tests/unit/graph/mock_toolkit_fix.py index af756b4b..3c46827d 100644 --- a/tests/unit/graph/mock_toolkit_fix.py +++ b/tests/unit/graph/mock_toolkit_fix.py @@ -32,13 +32,22 @@ def create_mock_toolkit_with_tools(): # Create mock for each method with proper __name__ attribute for method_name in tool_methods: - # Create a function with the right name - def mock_func(): - return f"Mock {method_name} data" + # Create a real function to satisfy @tool decorator requirements + def make_mock_func(name): + def mock_func(*args, **kwargs): + return f"Mock {name} data" - # Create Mock wrapping the function - mock_method = Mock(side_effect=mock_func) + mock_func.__name__ = name + mock_func.__qualname__ = name + return mock_func + + # Create the actual function (not a Mock) + actual_func = make_mock_func(method_name) + + # Wrap it in Mock for test assertions but keep function properties + mock_method = Mock(wraps=actual_func) mock_method.__name__ = method_name + mock_method.__qualname__ = method_name mock_method.name = method_name # Set it on the toolkit