Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 0 additions & 134 deletions tests/integrations/pydantic_ai/test_pydantic_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,41 +2358,6 @@ async def test_model_name_extraction_fallback_to_str(sentry_init, capture_items)
assert isinstance(result, str)


@pytest.mark.asyncio
async def test_model_settings_object_style(sentry_init, capture_items):
"""
Test that object-style model settings (non-dict) are handled correctly.
"""
from unittest.mock import MagicMock

import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_model_data

sentry_init(
integrations=[PydanticAIIntegration()],
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(op="test", name="test") as transaction:
span = sentry_sdk.start_span(op="test_span")

# Create mock settings object (not a dict)
mock_settings = MagicMock()
mock_settings.temperature = 0.8
mock_settings.max_tokens = 200
mock_settings.top_p = 0.95
mock_settings.frequency_penalty = 0.5
mock_settings.presence_penalty = 0.3

# Set model data with object-style settings
_set_model_data(span, None, mock_settings)

span.finish()

# Should not crash and should set the settings
assert transaction is not None


@pytest.mark.parametrize("span_streaming", [True, False])
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
@pytest.mark.asyncio
Expand Down Expand Up @@ -3397,105 +3362,6 @@ async def test_get_model_name_with_none(sentry_init, capture_items):
assert result is None


@pytest.mark.asyncio
async def test_set_model_data_with_system(sentry_init, capture_items):
"""
Test that _set_model_data captures system from model.
"""
from unittest.mock import MagicMock

import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_model_data

sentry_init(
integrations=[PydanticAIIntegration()],
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(op="test", name="test") as transaction:
span = sentry_sdk.start_span(op="test_span")

# Create model with system
mock_model = MagicMock()
mock_model.system = "openai"
mock_model.model_name = "gpt-4"

# Set model data
_set_model_data(span, mock_model, None)

span.finish()

# Should not crash
assert transaction is not None


@pytest.mark.asyncio
async def test_set_model_data_from_agent_scope(sentry_init, capture_items):
"""
Test that _set_model_data retrieves model from agent in scope when not passed.
"""
from unittest.mock import MagicMock

import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_model_data

sentry_init(
integrations=[PydanticAIIntegration()],
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(op="test", name="test") as transaction:
# Set agent in scope
scope = sentry_sdk.get_current_scope()
mock_agent = MagicMock()
mock_agent.model = MagicMock()
mock_agent.model.model_name = "test-model"
mock_agent.model_settings = {"temperature": 0.5}
scope._contexts["pydantic_ai_agent"] = {"_agent": mock_agent}

span = sentry_sdk.start_span(op="test_span")

# Pass None for model, should get from scope
_set_model_data(span, None, None)

span.finish()

# Should not crash
assert transaction is not None


@pytest.mark.asyncio
async def test_set_model_data_with_none_settings_values(sentry_init, capture_items):
"""
Test that _set_model_data skips None values in settings.
"""
import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_model_data

sentry_init(
integrations=[PydanticAIIntegration()],
traces_sample_rate=1.0,
)

with sentry_sdk.start_transaction(op="test", name="test") as transaction:
span = sentry_sdk.start_span(op="test_span")

# Create settings with None values
settings = {
"temperature": 0.7,
"max_tokens": None, # Should be skipped
"top_p": None, # Should be skipped
}

# Set model data
_set_model_data(span, None, settings)

span.finish()

# Should not crash
assert transaction is not None


@pytest.mark.asyncio
async def test_should_send_prompts_without_pii(sentry_init, capture_items):
"""
Expand Down
Loading