Skip to content

Commit 49988c2

Browse files
test(billing-cost-management-mcp-server): restore tool modules reloaded with an identity decorator (#4873)
The cost-allocation-tags, cost-category, storage-lens and unified-sql tests reload their tool module with FastMCP.tool patched to an identity decorator and never reload it back, so the module's server is left with no registered tools for every later test file. Each file now has a module-scoped fixture that reloads the real module after its tests, as the billing-conductor and cost-optimization-hub tests do.
1 parent a0d8304 commit 49988c2

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎src/billing-cost-management-mcp-server/tests/tools/test_cost_allocation_tags_tools.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@
3434
from unittest.mock import AsyncMock, MagicMock, patch
3535

3636

37+
@pytest.fixture(scope='module', autouse=True)
38+
def _restore_real_tool_module():
39+
"""Reload the module with the real FastMCP.tool after this file's tests.
40+
41+
_reload_with_identity_decorator() leaves the module's server with no registered tools;
42+
restoring it keeps later test files from seeing that state.
43+
"""
44+
yield
45+
from awslabs.billing_cost_management_mcp_server.tools import (
46+
cost_allocation_tags_tools as module,
47+
)
48+
49+
importlib.reload(module)
50+
51+
3752
def _reload_with_identity_decorator() -> Any:
3853
"""Reload module with FastMCP.tool patched to return the original function."""
3954
from awslabs.billing_cost_management_mcp_server.tools import (

‎src/billing-cost-management-mcp-server/tests/tools/test_cost_category_tools.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939
COST_CATEGORY_ARN = 'arn:aws:ce::123456789012:costcategory/abcd-1234-efgh-5678'
4040

4141

42+
@pytest.fixture(scope='module', autouse=True)
43+
def _restore_real_tool_module():
44+
"""Reload the module with the real FastMCP.tool after this file's tests.
45+
46+
_reload_with_identity_decorator() leaves the module's server with no registered tools;
47+
restoring it keeps later test files from seeing that state.
48+
"""
49+
yield
50+
from awslabs.billing_cost_management_mcp_server.tools import cost_category_tools as module
51+
52+
importlib.reload(module)
53+
54+
4255
def _reload_with_identity_decorator() -> Any:
4356
"""Reload module with FastMCP.tool patched to return the original function."""
4457
from awslabs.billing_cost_management_mcp_server.tools import cost_category_tools as mod

‎src/billing-cost-management-mcp-server/tests/tools/test_storage_lens_tools.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,19 @@ def test_server_initialization():
354354
)
355355

356356

357+
@pytest.fixture(scope='module', autouse=True)
358+
def _restore_real_tool_module():
359+
"""Reload the module with the real FastMCP.tool after this file's tests.
360+
361+
_reload_storage_lens_with_identity_decorator() leaves the module's server with no registered tools;
362+
restoring it keeps later test files from seeing that state.
363+
"""
364+
yield
365+
from awslabs.billing_cost_management_mcp_server.tools import storage_lens_tools as module
366+
367+
importlib.reload(module)
368+
369+
357370
def _reload_storage_lens_with_identity_decorator():
358371
"""Reload storage_lens_tools with FastMCP.tool patched to return the original function unchanged (identity decorator).
359372

‎src/billing-cost-management-mcp-server/tests/tools/test_unified_sql_tools.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ def test_unified_sql_server_initialization():
8181
assert unified_sql_server.name == 'unified-sql-tools'
8282

8383

84+
@pytest.fixture(scope='module', autouse=True)
85+
def _restore_real_tool_module():
86+
"""Reload the module with the real FastMCP.tool after this file's tests.
87+
88+
_reload_unified_sql_with_identity_decorator() leaves the module's server with no registered tools;
89+
restoring it keeps later test files from seeing that state.
90+
"""
91+
yield
92+
from awslabs.billing_cost_management_mcp_server.tools import unified_sql_tools as module
93+
94+
importlib.reload(module)
95+
96+
8497
def _reload_unified_sql_with_identity_decorator():
8598
"""Reload unified_sql_tools with FastMCP.tool patched to return the original function unchanged (identity decorator).
8699

0 commit comments

Comments
 (0)