Skip to content

# Refactor test_pydantic_ai to use public APIs (#5637)#5713

Open
harryautomazione wants to merge 2 commits intogetsentry:masterfrom
harryautomazione:fix-5637-pydantic-ai
Open

# Refactor test_pydantic_ai to use public APIs (#5637)#5713
harryautomazione wants to merge 2 commits intogetsentry:masterfrom
harryautomazione:fix-5637-pydantic-ai

Conversation

@harryautomazione
Copy link

What

  • Replaced all direct calls to the internal function _set_input_messages with higher-level public APIs, such as Agent.run(), or supported module-level wrappers (ai_client_span).
  • Removed fragile MagicMock setups and manual manipulation of internal message content representations in unit tests.

Why

How

  • test_input_messages_error_handling: Rewritten to pass invalid lists into ai_client_span, maintaining full coverage over the silent catch block logic.
  • test_message_parts_with_list_content: Refactored to triggers execution via static Agent.run(["item1", "item2"]) which models native structural parsing securely.
  • test_message_with_system_prompt_part: Refactored to pass history of real ModelRequest with SystemPromptPart directly to .run(message_history=...).
  • test_message_with_instructions: Preserved via module wrapper ai_client_span which bypasses internal calls without direct binding errors.
  • test_set_input_messages_without_prompts: Refactored to run the Agent on an integration initialized with include_prompts=False.

Testing

  • Setup isolated python VirtualEnv .venv.
  • Validated with local pytest:
    .venv\Scripts\pytest tests/integrations/pydantic_ai/test_pydantic_ai.py
  • Outcome: 100% tests Passed, no failures.

Risks / Impact

  • Risks: None. Changes operate purely in the test suite files.

Checklist

@harryautomazione harryautomazione requested a review from a team as a code owner March 19, 2026 21:25
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (asgi) Add option to disable suppressing chained exceptions by alexander-alderman-webb in #5714
  • (logging) Separate ignore lists for events/breadcrumbs and sentry logs by sl0thentr0py in #5698

Bug Fixes 🐛

Anthropic

  • Set exception info on streaming span when applicable by alexander-alderman-webb in #5683
  • Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans by alexander-alderman-webb in #5675
  • Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Documentation 📚

  • Add note on AI PRs to CONTRIBUTING.md by sentrivana in #5696

Internal Changes 🔧

  • Add -latest alias for each integration test suite by sentrivana in #5706
  • Use date-based branch names for toxgen PRs by sentrivana in #5704
  • 🤖 Update test matrix with new releases (03/19) by github-actions in #5703
  • Add client report tests for span streaming by sentrivana in #5677

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor test_pydantic_ai to remove usage of internal functions within tests

1 participant