Skip to content

fix: add close() method to HttpMockSequence for context manager support - #2684

Open
PupiBott wants to merge 1 commit into
googleapis:mainfrom
PupiBott:fix-http-mock-sequence-close-2359
Open

PupiBott wants to merge 1 commit into
googleapis:mainfrom
PupiBott:fix-http-mock-sequence-close-2359

Conversation

@PupiBott

@PupiBott PupiBott commented Nov 5, 2025

Copy link
Copy Markdown

Fixes #2359

HttpMockSequence is missing the close() method, causing AttributeError
when used with the context manager pattern recommended in the official
documentation.

Root cause: Commit 98888da (Sep 2020) added close() to HttpMock but
forgot to add it to HttpMockSequence.

This PR adds the close() method to HttpMockSequence following the same
no-op pattern as HttpMock.close(), ensuring compatibility with context
manager usage while maintaining backward compatibility.

Changes:

  • Added close() method to HttpMockSequence class
  • Added 5 comprehensive unit tests (100% pass rate)
  • No breaking changes introduced

Testing:
All new tests pass ✅ (5/5 in 0.41s)

Before (fails):
with build('drive', 'v3', http=HttpMockSequence([...])) as service:
pass # AttributeError: 'HttpMockSequence' object has no attribute 'close'

After (works):
with build('drive', 'v3', http=HttpMockSequence([...])) as service:
pass # ✅ Works perfectly

- Add close() method to HttpMockSequence class
- Implements no-op pattern consistent with HttpMock.close()
- Fixes AttributeError when using HttpMockSequence with context manager
- Add 5 comprehensive unit tests covering:
  * Method existence and callability
  * No-op behavior and multiple calls safety
  * Return value consistency (None)
  * Parity with HttpMock.close()
  * Usability after close()

All tests pass (5/5 in 0.33s)

Fixes googleapis#2359

Root cause: Commit 98888da (Sep 2020) added close() to HttpMock but
forgot to add it to HttpMockSequence. This PR completes that implementation.
@PupiBott
PupiBott requested review from a team November 5, 2025 01:21
@product-auto-label product-auto-label Bot added the size: m Pull request size is medium. label Nov 5, 2025

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpMockSequence is missing close() method

2 participants