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
89 changes: 0 additions & 89 deletions tests/integrations/pydantic_ai/test_pydantic_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3517,95 +3517,6 @@ async def test_should_send_prompts_without_pii(sentry_init, capture_items):
assert _should_send_outputs() is False


@pytest.mark.asyncio
async def test_set_agent_data_without_agent(sentry_init, capture_items):
"""
Test that _set_agent_data handles None agent gracefully.
"""
import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_agent_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")

# Pass None agent, with no agent in scope
_set_agent_data(span, None)

span.finish()

# Should not crash
assert transaction is not None


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

import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_agent_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.name = "test_agent_from_scope"
scope._contexts["pydantic_ai_agent"] = {"_agent": mock_agent}

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

# Pass None for agent, should get from scope
_set_agent_data(span, None)

span.finish()

# Should not crash
assert transaction is not None


@pytest.mark.asyncio
async def test_set_agent_data_without_name(sentry_init, capture_items):
"""
Test that _set_agent_data handles agent without name attribute.
"""
from unittest.mock import MagicMock

import sentry_sdk
from sentry_sdk.integrations.pydantic_ai.utils import _set_agent_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 agent without name
mock_agent = MagicMock()
mock_agent.name = None # No name

# Should not set agent name
_set_agent_data(span, mock_agent)

span.finish()

# Should not crash
assert transaction is not None


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