Skip to content

Conversation

@ningsuhen-lyra
Copy link

@ningsuhen-lyra ningsuhen-lyra commented Dec 11, 2025

Summary

This PR adds support for recording and playing back HTTP requests made via aiobotocore, the async version of boto3/botocore.

aiobotocore uses aiohttp internally but wraps responses in its own AioAWSResponse class. This implementation patches aiobotocore.httpsession.AIOHTTPSession.send to intercept requests and either:

  • Play back recorded responses from cassettes
  • Record real responses during recording mode
  • Raise CannotOverwriteExistingCassetteException when write-protected

Changes

  • New file: vcr/stubs/aiobotocore_stubs.py - Mock response classes (MockAioHTTPResponse, MockAioAWSResponse) and request/response handling
  • Modified: vcr/patch.py - Added aiobotocore patching to CassettePatcherBuilder
  • New file: tests/integration/test_aiobotocore.py - Integration tests for aiobotocore support

Implementation Notes

  • The mock response classes implement the interfaces expected by botocore's response parsing:

    • raw_headers property returning [(bytes, bytes), ...]
    • async read() method for body content
    • status_code, headers, and url attributes
  • aiobotocore has a circular import issue when importing aiobotocore.httpsession directly, so we import aiobotocore.session first to resolve the dependency graph

Test Plan

  • Basic cassette context manager works with aiobotocore
  • Playback from pre-recorded cassettes works correctly
  • Response body, headers, and status code are properly serialized/deserialized
  • Existing aiohttp tests still pass (no regressions)
  • Existing boto3 tests still pass (no regressions)

Related Issues

This enables testing of async AWS services using aiobotocore without making real network calls, similar to how vcrpy already supports boto3 (sync) and aiohttp.

ningsuhen-lyra and others added 2 commits December 10, 2025 21:42
This adds support for recording and playing back HTTP requests made via
aiobotocore, the async version of boto3/botocore. aiobotocore uses aiohttp
internally but wraps responses in its own AioAWSResponse class.

Changes:
- Add vcr/stubs/aiobotocore_stubs.py with mock response classes and
  request/response handling for aiobotocore's AIOHTTPSession.send method
- Update vcr/patch.py to patch aiobotocore.httpsession.AIOHTTPSession.send
- Add integration tests for aiobotocore in tests/integration/test_aiobotocore.py

The implementation follows the same pattern as the existing aiohttp stubs,
adapting the mock responses to work with botocore's expected response format
(url, status_code, headers dict, raw response with read() method).

Note: aiobotocore has a circular import issue when importing httpsession
directly, so we import aiobotocore.session first to avoid this.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

1 participant