Skip to content

fix(tests): skip aiohttp stub patches that fixed VCR.py doesn't need - #834

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
pylaterreur:vcrpy-1055-aiohttp-workaround
Oct 2, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
braintrustdata:mainfrom
pylaterreur:vcrpy-1055-aiohttp-workaround

Conversation

@pylaterreur

Copy link
Copy Markdown
Contributor

Summary

_patch_vcr_aiohttp_stubs() in py/src/braintrust/conftest.py works around kevin1024/vcrpy#927 and kevin1024/vcrpy#502. kevin1024/vcrpy#1055 (not released yet) fixes both and makes MockStream aiohttp's StreamReader, which takes the body. Our cached content property then calls MockStream() without a body, so aiohttp replays fail with TypeError: MockStream.__init__() missing 1 required positional argument: 'body', and pylint reports E1120. Nothing fails yet because py/uv.lock pins VCR.py 8.3.0, but the first weekly lock upgrade after a release with the fix would.

Changes

  • When MockStream is aiohttp's StreamReader, which only happens with the fix, skip the cached content property, the no-op set_exception and the record_response replacement. The fix isn't released yet, so a version number can't identify it, hence the class check. The stream_writer, iter_chunked and gzip text()/read() patches stay.
  • Silence pylint's no-value-for-parameter on the MockStream() call that only older VCR.py reaches.

On 8.3.0 the same attributes get the same code. With the fix, response.content is no longer gunzipped, which none of the 1,909 recorded responses needs.

Testing

Each nox session's tests, replaying cassettes with CI=1:

Session VCR.py 8.3.0 kevin1024/vcrpy#1055, before → after
test_litellm latest, 1.74.0 34 passed 14, 13 failed → 34 passed
test_huggingface_hub(0.32.0) 18 passed 3 failed → 18 passed
test_google_adk latest, 2.6.3, 1.14.1 15 passed 13, 12, 13 failed → 15 passed
test_google_genai(latest) with aiohttp 41 passed 9 failed → 41 passed
pylint --errors-only clean E1120 → clean

Recording LiteLLM, google-genai and huggingface_hub calls against a local server and replaying them also works on both versions. No new test: these sessions already reproduce the failure. Pre-commit hooks pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

_patch_vcr_aiohttp_stubs() works around kevin1024/vcrpy#927 and
kevin1024/vcrpy#502. kevin1024/vcrpy#1055 fixes both in VCR.py and
makes MockStream aiohttp's StreamReader, which takes the body. The
cached content property then calls MockStream() without one, so every
aiohttp replay fails with a TypeError and pylint reports E1120.

Skip the content property, the no-op set_exception and the
record_response replacement when MockStream is a StreamReader, which is
only true with that fix. VCR.py 8.3.0 gets the same patches as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
@AbhiPrasad

Copy link
Copy Markdown
Member

hey thanks for the PR! What led you to make this change?

@pylaterreur

Copy link
Copy Markdown
Contributor Author

hey thanks for the PR! What led you to make this change?

hey, np! Just happened to fix vcrpy, and stumbled upon this :) . Some more context in kevin1024/vcrpy#1055

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 6dd5034 into braintrustdata:main Oct 2, 2026
83 checks passed
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.

2 participants