Uh oh!
There was an error while loading. Please reload this page.
fix(storage): support updated GapicCallable metadata in tests - #18031
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the unit test test_init_default_client_info in test_read_client_v1.py to safely retrieve metadata from wrapped methods by checking _default_metadata before falling back to _metadata. This ensures the test is more resilient to changes in how metadata is stored on wrapped methods. There are no review comments, and I have no additional feedback to provide.
| ( | ||
| header_value | ||
| for header, header_value in wrapped_method._metadata | ||
| for header, header_value in metadata |
There was a problem hiding this comment.
Can you try to write this test in a way that doesn't depend on internal attributes? That would make it more resilient to these kinds of failures in the future
One option is to mock wrap_method:
@pytest.mark.parametrize(
"module_under_test",
["google.cloud.bigquery_storage_v1", "google.cloud.bigquery_storage_v1beta2"],
)
def test_init_default_client_info(module_under_test):
mut = importlib.import_module(module_under_test)
creds = mock.Mock(spec=credentials.Credentials)
expected_client_info = f"gccl/{mut.__version__}"
with mock.patch("google.api_core.gapic_v1.method.wrap_method") as mock_wrap:
mut.BigQueryWriteClient(credentials=creds)
assert mock_wrap.call_count > 0 # <- maybe set the expected number here? Or something more robust?
for call in mock_wrap.call_args_list:
client_info = call.kwargs.get("client_info")
assert client_info is not None
assert expected_client_info in client_info.to_user_agent()
There was a problem hiding this comment.
Thanks @daniel-sanche for the suggestion! Done.
4b57ac5 to
af634b0Compare
In google-api-core>=2.34.0 (PR #17616), _GapicCallable replaced the internal _metadata attribute with _default_metadata / _x_goog_api_client.
This PR updates test_init_default_client_info in packages/google-cloud-bigquery-storage/tests/unit/test_read_client_v1.py to check _default_metadata with a fallback to _metadata, maintaining compatibility across both older and newer google-api-core releases.
Fixes #<543999765> 🦕