test(pydantic_ai): Remove usage of internal functions from tests - #7622
Closed
DawnofGenX wants to merge 1 commit into
Closed
DawnofGenX wants to merge 1 commit into
DawnofGenX wants to merge 1 commit into
Conversation
Contributor
|
Going to close this because we don't have capacity to review the 5 PRs you've opened. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors
tests/integrations/pydantic_ai/test_pydantic_ai.pyso 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):_set_input_messages,_set_usage_data,_set_output_data,_set_available_tools,_get_model_namefrom the test module. Tests that exercised those helpers now drive the public integration surface:ai_client_span()/update_ai_client_span()(with realpydantic_aimessage/part objects —UserPromptPart,SystemPromptPart,ModelResponse,RequestUsage— instead ofMagicMockmessages), and read back the recorded data from the emitted chat span._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 wheninclude_prompts=False/PII off), so coverage is strictly increased.sentry_init-scoped assertions now use the integration's public helpersget_current_agent()/push_agent()/pop_agent()fromsentry_sdk.integrations.pydantic_ai.utilsinstead of pokingscope._contexts["pydantic_ai_agent"]. Note the SDK no longer stores agent state inScope._contextsat all (it is a private contextvar now), so every one of those_contextsassertions was vacuously true; they now verify the real mechanism. The two tests that injected fake streaming/agent state intoscope._contextswere rewritten to exerciseai_client_span()throughpush_agent()/streaming runs instead of injecting into a private dict.BLOB_DATA_SUBSTITUTEis now asserted as the literal wire value ("[Blob substitute]") with a comment, instead of importing the internal constant fromsentry_sdk._types(removes the lastfrom sentry_sdk._types import ...in the file).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:
No private-underscore usages remain (grep is empty; exit 1 = no match):
Lint:
Fixes #5637