Skip to content

fix(test): fix anthropic stream test mock missing get_final_message#2094

Merged
mkmeral merged 1 commit intostrands-agents:mainfrom
mkmeral:fix/anthropic-stream-test-mock
Apr 8, 2026
Merged

fix(test): fix anthropic stream test mock missing get_final_message#2094
mkmeral merged 1 commit intostrands-agents:mainfrom
mkmeral:fix/anthropic-stream-test-mock

Conversation

@agent-of-mkmeral
Copy link
Copy Markdown
Contributor

Problem

After #2047 introduced stream.get_final_message() in the Anthropic provider, the test_stream_message_stop_no_pydantic_warnings unit test started failing on Python 3.14 (failing run).

The test was manually constructing an async_generator as the stream mock via the agenerator fixture, which lacks the get_final_message() method. On Python 3.14, the async with context manager mock resolves differently, exposing this gap and causing:

AttributeError: 'async_generator' object has no attribute 'get_final_message'

Solution

Switched the test to use the existing generate_mock_stream_context helper, which properly creates a mock stream object with get_final_message support. This is consistent with how all other stream tests in the file are structured.

Related Issues

Type of Change

Bug fix (test)

Testing

  • Verified the test passes locally on Python 3.12
  • The fix uses the same generate_mock_stream_context helper used by all other stream tests in the file

The test_stream_message_stop_no_pydantic_warnings test was using a raw
async generator as the stream mock, which lacks get_final_message().
This caused an AttributeError on Python 3.14 after PR strands-agents#2047 introduced
stream.get_final_message() in the Anthropic provider.

Switch to generate_mock_stream_context helper which properly mocks the
stream object with get_final_message support.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mkmeral mkmeral disabled auto-merge April 8, 2026 18:39
@gautamsirdeshmukh
Copy link
Copy Markdown
Contributor

/strands review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Assessment: Approve

Clean, minimal fix that correctly aligns this test with the established mocking pattern used by all other stream tests in the file. The switch from a raw async_generator mock to generate_mock_stream_context properly provides get_final_message() support, and the final_message construction with usage.model_dump is consistent with the other tests (e.g., test_stream, test_stream_structured_output).

No issues found — LGTM.

@mkmeral mkmeral enabled auto-merge (squash) April 8, 2026 19:26
@mkmeral mkmeral merged commit cd5da4f into strands-agents:main Apr 8, 2026
30 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants