Skip to content

Commit 01d0619

Browse files
deduplicate
1 parent 95d15f6 commit 01d0619

File tree

4 files changed

+34
-51
lines changed

4 files changed

+34
-51
lines changed

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,30 @@ def suppress_deprecation_warnings():
592592
yield
593593

594594

595+
@pytest.fixture(
596+
params=[
597+
pytest.param(
598+
({"role": "system", "content": "You are helpful."}, "system"),
599+
id="system",
600+
),
601+
pytest.param(
602+
({"role": "user", "content": "Hello"}, "user"),
603+
id="user",
604+
),
605+
pytest.param(
606+
({"role": "ai", "content": "Hi there!"}, "assistant"),
607+
id="ai",
608+
),
609+
pytest.param(
610+
({"role": "assistant", "content": "How can I help?"}, "assistant"),
611+
id="assistant",
612+
),
613+
]
614+
)
615+
def input_ai_message_and_expected_role(request):
616+
return request.param
617+
618+
595619
class MockServerRequestHandler(BaseHTTPRequestHandler):
596620
def do_GET(self): # noqa: N802
597621
# Process an HTTP GET request and return a response.

tests/integrations/anthropic/test_anthropic.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -899,26 +899,14 @@ def test_set_output_data_with_input_json_delta(sentry_init):
899899
assert span._data.get(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS) == 30
900900

901901

902-
# Test messages with mixed roles including "ai" that should be mapped to "assistant"
903-
@pytest.mark.parametrize(
904-
"test_message,expected_role",
905-
[
906-
({"role": "system", "content": "You are helpful."}, "system"),
907-
({"role": "user", "content": "Hello"}, "user"),
908-
(
909-
{"role": "ai", "content": "Hi there!"},
910-
"assistant",
911-
), # Should be mapped to "assistant"
912-
(
913-
{"role": "assistant", "content": "How can I help?"},
914-
"assistant",
915-
), # Should stay "assistant"
916-
],
917-
)
918902
def test_anthropic_message_role_mapping(
919-
sentry_init, capture_events, test_message, expected_role
903+
sentry_init,
904+
capture_events,
905+
input_ai_message_and_expected_role,
920906
):
921907
"""Test that Anthropic integration properly maps message roles like 'ai' to 'assistant'"""
908+
test_message, expected_role = input_ai_message_and_expected_role
909+
922910
sentry_init(
923911
integrations=[AnthropicIntegration(include_prompts=True)],
924912
traces_sample_rate=1.0,

tests/integrations/openai/test_openai.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,26 +1457,11 @@ def test_empty_tools_in_chat_completion(sentry_init, capture_events, tools):
14571457
assert "gen_ai.request.available_tools" not in span["data"]
14581458

14591459

1460-
# Test messages with mixed roles including "ai" that should be mapped to "assistant"
1461-
@pytest.mark.parametrize(
1462-
"test_message,expected_role",
1463-
[
1464-
({"role": "system", "content": "You are helpful."}, "system"),
1465-
({"role": "user", "content": "Hello"}, "user"),
1466-
(
1467-
{"role": "ai", "content": "Hi there!"},
1468-
"assistant",
1469-
), # Should be mapped to "assistant"
1470-
(
1471-
{"role": "assistant", "content": "How can I help?"},
1472-
"assistant",
1473-
), # Should stay "assistant"
1474-
],
1475-
)
14761460
def test_openai_message_role_mapping(
1477-
sentry_init, capture_events, test_message, expected_role
1461+
sentry_init, capture_events, input_ai_message_and_expected_role
14781462
):
14791463
"""Test that OpenAI integration properly maps message roles like 'ai' to 'assistant'"""
1464+
test_message, expected_role = input_ai_message_and_expected_role
14801465

14811466
sentry_init(
14821467
integrations=[OpenAIIntegration(include_prompts=True)],

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,26 +1324,12 @@ async def run():
13241324
assert txn3["transaction"] == "test_agent workflow"
13251325

13261326

1327-
# Test input messages with mixed roles including "ai"
1328-
@pytest.mark.parametrize(
1329-
"test_message,expected_role",
1330-
[
1331-
({"role": "system", "content": "You are helpful."}, "system"),
1332-
({"role": "user", "content": "Hello"}, "user"),
1333-
(
1334-
{"role": "ai", "content": "Hi there!"},
1335-
"assistant",
1336-
), # Should be mapped to "assistant"
1337-
(
1338-
{"role": "assistant", "content": "How can I help?"},
1339-
"assistant",
1340-
), # Should stay "assistant"
1341-
],
1342-
)
13431327
def test_openai_agents_message_role_mapping(
1344-
sentry_init, capture_events, test_message, expected_role
1328+
sentry_init, capture_events, input_ai_message_and_expected_role
13451329
):
13461330
"""Test that OpenAI Agents integration properly maps message roles like 'ai' to 'assistant'"""
1331+
test_message, expected_role = input_ai_message_and_expected_role
1332+
13471333
sentry_init(
13481334
integrations=[OpenAIAgentsIntegration()],
13491335
traces_sample_rate=1.0,

0 commit comments

Comments
 (0)