GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(openai): Stop directly calling `_calculate_*_token_usage()` by alexander-alderman-webb · Pull Request #7875 · getsentry/sentry-python

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Oct 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Description

Exercise _calculate_completions_token_usage() and _calculate_responses_token_usage() by calling appropriate openai-python functions instead of reaching into SDK-internal functions.

Re-use model response fixtures, except for test_completions_token_usage_manual_output_counting_choices(), where a multi-choice output is provided inline.

Remove test_completions_token_usage_from_response(), whose token assertions are already in test_nonstreaming_chat_completion_no_prompts().

Remove test_responses_token_usage_from_response(), whose token assertions are already in test_ai_client_span_responses_api_no_pii().

Issues

Reminders

  • Please add tests to validate your changes, and lint your code using uv run ruff.
  • Add GH Issue ID & Linear ID (if applicable)
  • PR title should use conventional commit style (feat:, fix:, ref:, meta:)
  • For external contributors: CONTRIBUTING.md, Sentry SDK development docs, Discord community

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/openai/chat-completions-tokens branch from 1c01a08 to 414fcff Compare October 6, 2026 08:18
@github-actions

github-actions Bot commented Oct 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ 133417 passed | ⏭️ 7276 skipped | Total: 140693 | Pass Rate: 94.83% | Execution Time: 438m 42s

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2557 uncovered lines.


Generated by Codecov Action

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/openai/chat-completions-tokens branch 12 times, most recently from 727687d to 9740739 Compare October 6, 2026 09:29
@alexander-alderman-webb
test(openai): Stop directly calling _calculate_completions_token_usage()
a810175
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/openai/chat-completions-tokens branch from 9740739 to a810175 Compare October 6, 2026 09:35
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review October 6, 2026 09:45
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner October 6, 2026 09:45
sentrivana
sentrivana approved these changes Oct 6, 2026
View reviewed changes
@alexander-alderman-webb
Use nonstreaming_responses_model_response fixture
2c7ae65
@alexander-alderman-webb alexander-alderman-webb changed the title test(openai): Stop directly calling _calculate_completions_token_usage() test(openai): Stop directly calling _calculate_*_token_usage() Oct 6, 2026
alexander-alderman-webb added 5 commits October 6, 2026 14:57
@alexander-alderman-webb
add types
b4f3688
@alexander-alderman-webb
fix model input
3139530
@alexander-alderman-webb
parametrize tomkens in streaming fixture
7a440e4
@alexander-alderman-webb
.
2d16b1a
@alexander-alderman-webb
preserve existing response chunks
584e80d
cursor[bot]
cursor Bot reviewed Oct 6, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this 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.

Reviewed by Cursor Bugbot for commit 584e80d. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/integrations/litellm/test_litellm.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb
.
f80a3b6
@alexander-alderman-webb
alexander-alderman-webb merged commit b5737a0 into master Oct 6, 2026
166 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-alderman-webb
alexander-alderman-webb deleted the webb/openai/chat-completions-tokens branch October 6, 2026 14:51
@sentry-release-bot sentry-release-bot Bot mentioned this pull request Oct 12, 2026
publish: getsentry/[email protected] getsentry/publish#9830
Closed
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@sentrivana sentrivana sentrivana approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@alexander-alderman-webb @sentrivana
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.