Title: test(pydantic_ai): Remove usage of internal functions from tests by DawnofGenX · Pull Request #7622 · getsentry/sentry-python · GitHub
Open Graph Title: test(pydantic_ai): Remove usage of internal functions from tests by DawnofGenX · Pull Request #7622 · getsentry/sentry-python
X Title: test(pydantic_ai): Remove usage of internal functions from tests by DawnofGenX · Pull Request #7622 · getsentry/sentry-python
Description: Summary
Refactors tests/integrations/pydantic_ai/test_pydantic_ai.py so it no longer imports or calls internal (_-prefixed) SDK functions, per CONTRIBUTING ("Don't call private functions") and the review note in #5629. Fixes #5637.
What changed (test-only; no sentry_sdk/ changes):
Removed imports/calls of _set_input_messages, _set_usage_data, _set_output_data, _set_available_tools, _get_model_name from the test module. Tests that exercised those helpers now drive the public integration surface: ai_client_span() / update_ai_client_span() (with real pydantic_ai message/part objects — UserPromptPart, SystemPromptPart, ModelResponse, RequestUsage — instead of MagicMock messages), and read back the recorded data from the emitted chat span.
Several of these tests were previously vacuous (_set_input_messages(span, msgs) + assert transaction is not None — no assertion on captured data). They now assert the actual span attributes (gen_ai.request.messages, gen_ai.system.instructions, gen_ai.request.model, gen_ai.usage.*, gen_ai.request.available_tools, absence of messages when include_prompts=False/PII off), so coverage is strictly increased.
Agent-context tests: sentry_init-scoped assertions now use the integration's public helpers get_current_agent()/push_agent()/pop_agent() from sentry_sdk.integrations.pydantic_ai.utils instead of poking scope._contexts["pydantic_ai_agent"]. Note the SDK no longer stores agent state in Scope._contexts at all (it is a private contextvar now), so every one of those _contexts assertions was vacuously true; they now verify the real mechanism. The two tests that injected fake streaming/agent state into scope._contexts were rewritten to exercise ai_client_span() through push_agent()/streaming runs instead of injecting into a private dict.
BLOB_DATA_SUBSTITUTE is now asserted as the literal wire value ("[Blob substitute]") with a comment, instead of importing the internal constant from sentry_sdk._types (removes the last from sentry_sdk._types import ... in the file).
Renamed two tests whose names referenced internal functions (test_get_model_name_* → test_model_name_*, test_set_usage_data_with_cache_tokens → test_usage_data_with_cache_tokens).
Test plan
Full integration suite green on both supported pydantic-ai pins after refactor:
$ TESTPATH=tests/integrations/pydantic_ai uv run tox -e py3.14-pydantic_ai-latest
====================== 331 passed, 69 warnings in 12.57s =======================
py3.14-pydantic_ai-latest: OK
$ TESTPATH=tests/integrations/pydantic_ai uv run tox -e py3.10-pydantic_ai-v1.0.18
====================== 331 passed, 68 warnings in 35.07s =======================
py3.10-pydantic_ai-v1.0.18: OK
No private-underscore usages remain (grep is empty; exit 1 = no match):
$ grep -nE "_set_|_should_send_prompts|_get_model_name|_get_context|_get_tool_def|_contexts|from sentry_sdk\._|import _" tests/integrations/pydantic_ai/test_pydantic_ai.py
GREP_EXIT=1
Lint:
$ uv run ruff check tests
All checks passed!
$ uv run ruff format tests
Open Graph Description: Summary Refactors tests/integrations/pydantic_ai/test_pydantic_ai.py so it no longer imports or calls internal (_-prefixed) SDK functions, per CONTRIBUTING ("Don't call private functions&q...
X Description: Summary Refactors tests/integrations/pydantic_ai/test_pydantic_ai.py so it no longer imports or calls internal (_-prefixed) SDK functions, per CONTRIBUTING ("Don't call private fun...
Opengraph URL: https://github.com/getsentry/sentry-python/pull/7622
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ea1db893-a05a-cb02-858e-ccf7bc0d7f59 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 88C4:19F84C:963BFE:C30B4E:6B00DE58 |
| html-safe-nonce | 8898264e03cd8e62dc7242005ffa75a302ac9dc7a2f0970ea88a8c7c74ba6959 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEM0OjE5Rjg0Qzo5NjNCRkU6QzMwQjRFOjZCMDBERTU4IiwidmlzaXRvcl9pZCI6IjE1MDMxMTY3ODg3Nzc0MTAxMzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b9fc0fdb36c4680a24537e2e453711cd8d199be527070895627128e36fa3d2e3 |
| hovercard-subject-tag | pull_request:4606724211 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/getsentry/sentry-python/pull/7622/files |
| twitter:image | https://avatars.githubusercontent.com/u/97001446?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/97001446?s=400&v=4 |
| og:image:alt | Summary Refactors tests/integrations/pydantic_ai/test_pydantic_ai.py so it no longer imports or calls internal (_-prefixed) SDK functions, per CONTRIBUTING ("Don't call private functions&q... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width