FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tests: handle internal metadata changes in google-api-core by chalmerlowe · Pull Request #18037 · googleapis/google-cloud-python · GitHub

tests: handle internal metadata changes in google-api-core - #18037

Merged
parthea merged 1 commit into
mainfrom
fix/pubsub-gapic-callable-metadata
Aug 10, 2026
Merged

tests: handle internal metadata changes in google-api-core#18037
parthea merged 1 commit into
mainfrom
fix/pubsub-gapic-callable-metadata

Conversation

chalmerlowe commented Aug 10, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Problem

The test_init_default_client_info tests in google-cloud-pubsub (for both Publisher and Subscriber) were brittle because they peeked into the private internal attributes of _GapicCallable (from google-api-core) to verify metadata.
Recent refactoring in google-api-core renamed/removed the _metadata attribute, causing these tests to fail with AttributeError: '_GapicCallable' object has no attribute '_metadata'.

Solution

Refactored test_init_default_client_info in test_publisher_client.py and test_subscriber_client.py to use mocking instead of peeking into internal state.

  • The tests now use unittest.mock.patch to intercept calls to google.api_core.gapic_v1.method.wrap_method.
  • We verify that wrap_method is called with the expected client_info object.
  • We assert that the client_info contains the correct library version string (e.g., gccl/x.y.z).

Why this is important

  • Robustness: Tests are no longer dependent on internal implementation details or private attributes of downstream libraries (google-api-core).
  • Future-Proof: Prevents test failures when internal state is refactored, as long as the public-facing helper signature (wrap_method) remains stable.
  • Consistency: Aligns with the testing patterns already adopted by other modern clients in this monorepo (e.g., google-cloud-bigquery-storage).

Blocks: #17642

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request updates the unit tests for both the publisher and subscriber clients to handle internal changes in the google-api-core library's _GapicCallable. Specifically, it safely retrieves metadata from wrapped methods by falling back to _default_metadata if _metadata is not present. Additionally, some minor import cleanups were performed. There are no review comments, and I have no feedback to provide.

chalmerlowe marked this pull request as ready for review August 10, 2026 10:17
chalmerlowe requested a review from a team as a code owner August 10, 2026 10:17
parthea changed the title fix(pubsub): handle internal metadata changes in google-api-core tests: handle internal metadata changes in google-api-core Aug 10, 2026
parthea merged commit b8f6776 into main Aug 10, 2026
43 checks passed
parthea deleted the fix/pubsub-gapic-callable-metadata branch August 10, 2026 15:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL