googleapis / gapic-generator-python

Generate Python API client libraries from Protocol Buffers.
Apache License 2.0
121 stars 66 forks source link

Generated Code breaks unit tests of repositories containing handwritten layers wrapping Gapic #2053

Open mukund-ananthu opened 3 months ago

mukund-ananthu commented 3 months ago

Ask: Generator code could have presubmits that ensure that dependent handwritten repository unit tests are not broken.

Example Link:https://github.com/googleapis/python-pubsub/actions/runs/9765604292/job/26956649154?pr=1154

Example test failures:

______________ test_sync_pull_warning_if_return_immediately_async ______________

creds = <google.auth.credentials.AnonymousCredentials object at 0x7f4e5dee8250>

    @pytest.mark.asyncio
    async def test_sync_pull_warning_if_return_immediately_async(creds):
        from google.pubsub_v1.services.subscriber.async_client import SubscriberAsyncClient

        client = SubscriberAsyncClient(credentials=creds)
        subscription_path = "projects/foo/subscriptions/bar"

        patcher = mock.patch(
            "google.pubsub_v1.services.subscriber.async_client.gapic_v1.method_async.wrap_method",
            new=mock.AsyncMock,
        )

        with patcher, pytest.warns(
            DeprecationWarning,
            match="The return_immediately flag is deprecated and should be set to False",
        ) as warned:
>           await client.pull(subscription=subscription_path, return_immediately=True)

tests/unit/pubsub_v1/subscriber/test_subscriber_client.py:311: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
google/pubsub_v1/services/subscriber/async_client.py:1289: in pull
    response = await rpc(
.nox/unit-3-9/lib/python3.9/site-packages/google/api_core/retry/retry_unary_async.py:230: in retry_wrapped_func
    return await retry_target(
.nox/unit-3-9/lib/python3.9/site-packages/google/api_core/retry/retry_unary_async.py:160: in retry_target
    _retry_error_helper(
.nox/unit-3-9/lib/python3.9/site-packages/google/api_core/retry/retry_base.py:212: in _retry_error_helper
    raise final_exc from source_exc
.nox/unit-3-9/lib/python3.9/site-packages/google/api_core/retry/retry_unary_async.py:155: in retry_target
    return await target()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <google.api_core.grpc_helpers_async._WrappedUnaryUnaryCall object at 0x7f4e5da7[46](https://github.com/googleapis/python-pubsub/actions/runs/9765604292/job/26956649154?pr=1154#step:5:47)d0>

    def __await__(self) -> Iterator[P]:
        try:
            response = yield from self._call.__await__()
            return response
        except grpc.RpcError as rpc_error:
>           raise exceptions.from_grpc_error(rpc_error) from rpc_error
E           google.api_core.exceptions.PermissionDenied: 403 The request is missing a valid API key.

.nox/unit-3-9/lib/python3.9/site-packages/google/api_core/grpc_helpers_async.py:88: PermissionDenied
- generated xml file: /home/runner/work/python-pubsub/python-pubsub/unit_3.9_sponge_log.xml -
=========================== short test summary info ============================
FAILED tests/unit/pubsub_v1/subscriber/test_subscriber_client.py::test_sync_pull_warning_if_return_immediately_async - google.api_core.exceptions.PermissionDenied: 403 The request is missing a valid API key.
1 failed, 16[52](https://github.com/googleapis/python-pubsub/actions/runs/9765604292/job/26956649154?pr=1154#step:5:53) passed in 21.35s
nox > Command py.test --quiet --junitxml=unit_3.9_sponge_log.xml --cov=google/cloud --cov=tests/unit --cov-append --cov-config=.coveragerc --cov-report= --cov-fail-under=0 tests/unit failed with exit code 1
nox > Session unit-3.9 failed.
mukund-ananthu commented 3 months ago

cc: @parthea