Skip to content

Commit 4ebe3ca

Browse files
committed
Cleanup tests.
1 parent 1256774 commit 4ebe3ca

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

tests/mlmodel_langchain/test_agents.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import pytest
1616
from langchain.messages import HumanMessage
1717
from langchain.tools import tool
18-
from testing_support.fixtures import reset_core_stats_engine, validate_attributes
18+
from testing_support.fixtures import dt_enabled, reset_core_stats_engine, validate_attributes
1919
from testing_support.ml_testing_utils import (
2020
disabled_ai_monitoring_record_content_settings,
2121
disabled_ai_monitoring_settings,
@@ -77,6 +77,7 @@ def add_exclamation(message: str) -> str:
7777
return f"{message}!"
7878

7979

80+
@dt_enabled
8081
@reset_core_stats_engine()
8182
def test_agent(exercise_agent, create_agent_runnable, set_trace_info, method_name):
8283
@validate_custom_events(events_with_context_attrs(agent_recorded_event))
@@ -103,6 +104,7 @@ def _test():
103104
_test()
104105

105106

107+
@dt_enabled
106108
@reset_core_stats_engine()
107109
@disabled_ai_monitoring_record_content_settings
108110
def test_agent_no_content(exercise_agent, create_agent_runnable, set_trace_info, method_name):
@@ -128,13 +130,15 @@ def _test():
128130
_test()
129131

130132

133+
@dt_enabled
131134
@reset_core_stats_engine()
132135
@validate_custom_event_count(count=0)
133136
def test_agent_outside_txn(exercise_agent, create_agent_runnable):
134137
my_agent = create_agent_runnable(tools=[add_exclamation], system_prompt="You are a text manipulation algorithm.")
135138
exercise_agent(my_agent, PROMPT)
136139

137140

141+
@dt_enabled
138142
@disabled_ai_monitoring_settings
139143
@reset_core_stats_engine()
140144
@validate_custom_event_count(count=0)
@@ -145,6 +149,7 @@ def test_agent_disabled_ai_monitoring_events(exercise_agent, create_agent_runnab
145149
exercise_agent(my_agent, PROMPT)
146150

147151

152+
@dt_enabled
148153
@reset_core_stats_engine()
149154
def test_agent_execution_error(exercise_agent, create_agent_runnable, set_trace_info, method_name, agent_runnable_type):
150155
# Add a wrapper to intentionally force an error in the Agent code
@@ -164,8 +169,8 @@ def inject_exception(wrapped, instance, args, kwargs):
164169
background_task=True,
165170
)
166171
@validate_attributes("agent", ["llm"])
172+
# Only an agent span is expected here and not a tool because the error is injected before the tool is called
167173
@validate_span_events(count=1, exact_agents={"subcomponent": '{"type": "APM-AI_AGENT", "name": "my_agent"}'})
168-
@validate_span_events(count=1, exact_agents={"subcomponent": '{"type": "APM-AI_TOOL", "name": "add_exclamation"}'})
169174
@background_task(name="test_agent_execution_error")
170175
def _test():
171176
set_trace_info()

tests/mlmodel_langchain/test_tools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import pytest
1616
from langchain.messages import HumanMessage
17-
from testing_support.fixtures import reset_core_stats_engine, validate_attributes
17+
from testing_support.fixtures import dt_enabled, reset_core_stats_engine, validate_attributes
1818
from testing_support.ml_testing_utils import (
1919
disabled_ai_monitoring_record_content_settings,
2020
events_with_context_attrs,
@@ -96,6 +96,7 @@
9696
]
9797

9898

99+
@dt_enabled
99100
@reset_core_stats_engine()
100101
def test_tool(exercise_agent, set_trace_info, create_agent_runnable, add_exclamation, tool_method_name):
101102
@validate_custom_events(events_with_context_attrs(tool_recorded_event))
@@ -122,6 +123,7 @@ def _test():
122123
_test()
123124

124125

126+
@dt_enabled
125127
@reset_core_stats_engine()
126128
@disabled_ai_monitoring_record_content_settings
127129
def test_tool_no_content(exercise_agent, set_trace_info, create_agent_runnable, add_exclamation, tool_method_name):
@@ -147,6 +149,7 @@ def _test():
147149
_test()
148150

149151

152+
@dt_enabled
150153
@reset_core_stats_engine()
151154
def test_tool_execution_error(exercise_agent, set_trace_info, create_agent_runnable, add_exclamation, tool_method_name):
152155
@validate_transaction_error_event_count(1)
@@ -176,6 +179,7 @@ def _test():
176179
_test()
177180

178181

182+
@dt_enabled
179183
@reset_core_stats_engine()
180184
def test_tool_pre_execution_exception(
181185
exercise_agent, set_trace_info, create_agent_runnable, add_exclamation, tool_method_name

0 commit comments

Comments
 (0)