Skip to content

fix(test): mock headers in test_completion_fine_tuned_model - #25444

Merged
yuneng-berri merged 2 commits into
BerriAI:mainfrom
joereyna:litellm_fix_vertex_fine_tuned_model_test
Apr 10, 2026
Merged

fix(test): mock headers in test_completion_fine_tuned_model#25444
yuneng-berri merged 2 commits into
BerriAI:mainfrom
joereyna:litellm_fix_vertex_fine_tuned_model_test

Conversation

@joereyna

@joereyna joereyna commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • mock_response = AsyncMock() left headers as an AsyncMock attribute
  • raw_response.headers.get("x-gemini-service-tier") returned a truthy AsyncMock, so the walrus operator assigned it to service_tier
  • service_tier.lower() then failed with AttributeError: 'coroutine' object has no attribute 'lower'
  • Fix: set mock_response.headers = {} so the header lookup returns None and the service tier branch is skipped

Test plan

  • test_completion_fine_tuned_model passes in CI (requires real GCP credentials)

@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 9, 2026 10:30pm

Request Review

@greptile-apps

greptile-apps Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a spurious AttributeError in test_completion_fine_tuned_model caused by AsyncMock auto-creating a truthy AsyncMock object for headers, which then flowed into a .lower() call on what the code expected to be a string. The fix sets mock_response.headers = {} and hoists mock_response.status_code = 200 earlier, making the mock faithfully represent a real HTTP response. The remaining whitespace-only removals are cosmetic cleanup.

Confidence Score: 5/5

Safe to merge — fixes a broken test mock with no production code changes.

The only functional change is setting headers = {} on an AsyncMock to prevent a spurious AttributeError; all test assertions remain unchanged and test coverage is not weakened. The rest of the diff is cosmetic whitespace removal.

No files require special attention.

Important Files Changed

Filename Overview
tests/local_testing/test_amazing_vertex_completion.py Fixes broken AsyncMock by explicitly setting headers = {} and status_code = 200 upfront; remaining changes are cosmetic blank-line removals.

Sequence Diagram

sequenceDiagram
    participant Test as test_completion_fine_tuned_model
    participant LiteLLM as litellm.acompletion
    participant Handler as AsyncHTTPHandler.post (patched)
    participant Mock as mock_response

    Test->>Mock: headers = {} (NEW)
    Test->>Mock: status_code = 200
    Test->>Mock: json = return_val
    Test->>LiteLLM: acompletion(model, messages)
    LiteLLM->>Handler: POST request (mocked)
    Handler-->>LiteLLM: mock_response
    LiteLLM->>Mock: headers.get("x-gemini-service-tier")
    Mock-->>LiteLLM: None (empty dict, no branch taken)
    LiteLLM->>Mock: json() → response dict
    LiteLLM-->>Test: ModelResponse
    Test->>Test: assert URL, payload, response fields
Loading

Reviews (2): Last reviewed commit: "format vertex test file" | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing joereyna:litellm_fix_vertex_fine_tuned_model_test (afd46e7) with main (3a6db70)

Open in CodSpeed

@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Bakul2006

Copy link
Copy Markdown

Hey, @joereyna Are you facing the same issue of formatting the 330 files in lint check

@joereyna

joereyna commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Hey, @joereyna Are you facing the same issue of formatting the 330 files in lint check

Yes, seeing the same thing.

@yuneng-berri

Copy link
Copy Markdown
Contributor

@Bakul2006 this is a known issue, we are actively making the dev process more seamless around this.

@yuneng-berri
yuneng-berri self-requested a review April 10, 2026 00:36
@yuneng-berri
yuneng-berri merged commit e7551a1 into BerriAI:main Apr 10, 2026
49 of 51 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…e_tuned_model_test

fix(test): mock headers in test_completion_fine_tuned_model
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.

3 participants