@@ -1010,8 +1010,14 @@ def test_agent_init_with_trace_attributes():
10101010 assert "invalid_nested_list" not in agent .trace_attributes
10111011
10121012
1013+ @pytest .fixture
1014+ def mock_metrics_client ():
1015+ with unittest .mock .patch ("strands.agent.agent.MetricsClient" ) as mock_metrics_client :
1016+ yield mock_metrics_client
1017+
1018+
10131019@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1014- def test_agent_init_initializes_tracer (mock_get_tracer ):
1020+ def test_agent_init_initializes_tracer (mock_get_tracer , mock_metrics_client ):
10151021 """Test that the tracer is initialized when creating an Agent."""
10161022 mock_tracer = unittest .mock .MagicMock ()
10171023 mock_get_tracer .return_value = mock_tracer
@@ -1025,7 +1031,7 @@ def test_agent_init_initializes_tracer(mock_get_tracer):
10251031
10261032
10271033@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1028- def test_agent_call_creates_and_ends_span_on_success (mock_get_tracer , mock_model ):
1034+ def test_agent_call_creates_and_ends_span_on_success (mock_get_tracer , mock_metrics_client , mock_model ):
10291035 """Test that __call__ creates and ends a span when the call succeeds."""
10301036 # Setup mock tracer and span
10311037 mock_tracer = unittest .mock .MagicMock ()
@@ -1060,7 +1066,9 @@ def test_agent_call_creates_and_ends_span_on_success(mock_get_tracer, mock_model
10601066
10611067@pytest .mark .asyncio
10621068@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1063- async def test_agent_stream_async_creates_and_ends_span_on_success (mock_get_tracer , mock_event_loop_cycle ):
1069+ async def test_agent_stream_async_creates_and_ends_span_on_success (
1070+ mock_get_tracer , mock_metrics_client , mock_event_loop_cycle
1071+ ):
10641072 """Test that stream_async creates and ends a span when the call succeeds."""
10651073 # Setup mock tracer and span
10661074 mock_tracer = unittest .mock .MagicMock ()
@@ -1105,7 +1113,7 @@ def call_callback_handler(*args, **kwargs):
11051113
11061114
11071115@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1108- def test_agent_call_creates_and_ends_span_on_exception (mock_get_tracer , mock_model ):
1116+ def test_agent_call_creates_and_ends_span_on_exception (mock_get_tracer , mock_metrics_client , mock_model ):
11091117 """Test that __call__ creates and ends a span when an exception occurs."""
11101118 # Setup mock tracer and span
11111119 mock_tracer = unittest .mock .MagicMock ()
@@ -1139,7 +1147,7 @@ def test_agent_call_creates_and_ends_span_on_exception(mock_get_tracer, mock_mod
11391147
11401148@pytest .mark .asyncio
11411149@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1142- async def test_agent_stream_async_creates_and_ends_span_on_exception (mock_get_tracer , mock_model ):
1150+ async def test_agent_stream_async_creates_and_ends_span_on_exception (mock_get_tracer , mock_metrics_client , mock_model ):
11431151 """Test that stream_async creates and ends a span when the call succeeds."""
11441152 # Setup mock tracer and span
11451153 mock_tracer = unittest .mock .MagicMock ()
@@ -1174,7 +1182,7 @@ async def test_agent_stream_async_creates_and_ends_span_on_exception(mock_get_tr
11741182
11751183
11761184@unittest .mock .patch ("strands.agent.agent.get_tracer" )
1177- def test_event_loop_cycle_includes_parent_span (mock_get_tracer , mock_event_loop_cycle , mock_model ):
1185+ def test_event_loop_cycle_includes_parent_span (mock_get_tracer , mock_metrics_client , mock_event_loop_cycle , mock_model ):
11781186 """Test that event_loop_cycle is called with the parent span."""
11791187 # Setup mock tracer and span
11801188 mock_tracer = unittest .mock .MagicMock ()
0 commit comments