From c9c58b548791963c4e60a89921829ed2fa633f1d Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Tue, 12 Aug 2025 15:45:14 -0700 Subject: [PATCH 1/8] Try to fix fragment (3.13) tests by pinning pytest-asyncio --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 7b686cb7db..710f07edf2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -167,7 +167,7 @@ def fragment(session, use_ads_templates=False): "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio", + "pytest-asyncio < '1.1.0'", "grpcio-tools", ) session.install("-e", ".") @@ -480,7 +480,7 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio", + "pytest-asyncio < '1.1.0'", ) # Run the tests. # NOTE: async rest is not supported against the minimum supported version of google-api-core. From 261299445047c834f29d6474ac0266c4cae54a81 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 08:29:03 -0700 Subject: [PATCH 2/8] fix: import and use asyncio for async service test --- gapic/templates/noxfile.py.j2 | 1 + .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 4 +++- noxfile.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index 6408f306dc..5991bd18c2 100644 --- a/gapic/templates/noxfile.py.j2 +++ b/gapic/templates/noxfile.py.j2 @@ -55,6 +55,7 @@ SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index a69026767c..32a16f55d4 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -226,6 +226,7 @@ def test__get_api_endpoint(): {% for method in service.methods.values() %}{% with method_name = method.name|snake_case %} {% for mode in ["", "async"] %} {% if mode == "async" %} +@pytest.mark.asyncio async def test_{{ method_name }}_api_version_header_async(transport_name="grpc"): client = {{ service.async_client_name }}(credentials=async_anonymous_credentials(), transport=transport_name) {% else %} @@ -247,7 +248,8 @@ def test_{{ method_name }}_api_version_header(transport_name): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.{{ method.transport_safe_name|snake_case }}), - '__call__' + '__call__'{% if mode == "async" %}, + new_callable=AsyncMock{% endif %} ) as call: {% if mode == "async" %} await client.{{ method_name }}() diff --git a/noxfile.py b/noxfile.py index 710f07edf2..821229f7e3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -167,7 +167,7 @@ def fragment(session, use_ads_templates=False): "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio < '1.1.0'", + "pytest-asyncio<1.1.0", "grpcio-tools", ) session.install("-e", ".") @@ -480,7 +480,7 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio < '1.1.0'", + "pytest-asyncio<1.1.0", ) # Run the tests. # NOTE: async rest is not supported against the minimum supported version of google-api-core. From c37eca7c35236d0cf53681ec27ba72f777c4751e Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 11:06:36 -0700 Subject: [PATCH 3/8] unpin the pytest-asyncio version --- noxfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 821229f7e3..7b686cb7db 100644 --- a/noxfile.py +++ b/noxfile.py @@ -167,7 +167,7 @@ def fragment(session, use_ads_templates=False): "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio<1.1.0", + "pytest-asyncio", "grpcio-tools", ) session.install("-e", ".") @@ -480,7 +480,7 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False "pytest-cov", "pytest-xdist", "asyncmock; python_version < '3.8'", - "pytest-asyncio<1.1.0", + "pytest-asyncio", ) # Run the tests. # NOTE: async rest is not supported against the minimum supported version of google-api-core. From 14c56f98b3cf3f9a68ab15e11f6f85a0859ebc43 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 14:45:33 -0700 Subject: [PATCH 4/8] Update goldens --- tests/integration/goldens/asset/noxfile.py | 1 + tests/integration/goldens/credentials/noxfile.py | 1 + tests/integration/goldens/eventarc/noxfile.py | 1 + tests/integration/goldens/logging/noxfile.py | 1 + tests/integration/goldens/logging_internal/noxfile.py | 1 + tests/integration/goldens/redis/noxfile.py | 1 + tests/integration/goldens/redis_selective/noxfile.py | 1 + 7 files changed, 7 insertions(+) diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index 4efb1b1161..b8871714dc 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/credentials/noxfile.py b/tests/integration/goldens/credentials/noxfile.py index 3aea2c0c1b..7d5fb2cdef 100755 --- a/tests/integration/goldens/credentials/noxfile.py +++ b/tests/integration/goldens/credentials/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/eventarc/noxfile.py b/tests/integration/goldens/eventarc/noxfile.py index ba8fbf5fc2..ea18dc4ecb 100755 --- a/tests/integration/goldens/eventarc/noxfile.py +++ b/tests/integration/goldens/eventarc/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/logging/noxfile.py b/tests/integration/goldens/logging/noxfile.py index 2e9dd52f17..9899a7348c 100755 --- a/tests/integration/goldens/logging/noxfile.py +++ b/tests/integration/goldens/logging/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/logging_internal/noxfile.py b/tests/integration/goldens/logging_internal/noxfile.py index 2e9dd52f17..9899a7348c 100755 --- a/tests/integration/goldens/logging_internal/noxfile.py +++ b/tests/integration/goldens/logging_internal/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/redis/noxfile.py b/tests/integration/goldens/redis/noxfile.py index 5768044661..c8733082e0 100755 --- a/tests/integration/goldens/redis/noxfile.py +++ b/tests/integration/goldens/redis/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] diff --git a/tests/integration/goldens/redis_selective/noxfile.py b/tests/integration/goldens/redis_selective/noxfile.py index 5768044661..c8733082e0 100755 --- a/tests/integration/goldens/redis_selective/noxfile.py +++ b/tests/integration/goldens/redis_selective/noxfile.py @@ -62,6 +62,7 @@ SYSTEM_TEST_STANDARD_DEPENDENCIES = [ "mock", "pytest", + "pytest-asyncio" "google-cloud-testutils", ] SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] From 9b182cfa4d714ae11aee0109036503c885390c4b Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 16:58:04 -0700 Subject: [PATCH 5/8] pin mypy --- gapic/templates/noxfile.py.j2 | 3 ++- noxfile.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index 5991bd18c2..d8b637b332 100644 --- a/gapic/templates/noxfile.py.j2 +++ b/gapic/templates/noxfile.py.j2 @@ -82,7 +82,8 @@ nox.options.error_on_missing_interpreters = True def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/noxfile.py b/noxfile.py index 7b686cb7db..8d02b33dbd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -589,7 +589,8 @@ def showcase_mypy( """Perform typecheck analysis on the generated Showcase library.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-setuptools", "types-protobuf", "types-requests", From 21572357ac455051fff0d13f8627c72c4365e05a Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 17:01:30 -0700 Subject: [PATCH 6/8] Update goldens --- tests/integration/goldens/asset/noxfile.py | 3 ++- tests/integration/goldens/credentials/noxfile.py | 3 ++- tests/integration/goldens/eventarc/noxfile.py | 3 ++- tests/integration/goldens/logging/noxfile.py | 3 ++- tests/integration/goldens/logging_internal/noxfile.py | 3 ++- tests/integration/goldens/redis/noxfile.py | 3 ++- tests/integration/goldens/redis_selective/noxfile.py | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index b8871714dc..cd82d70fc3 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/credentials/noxfile.py b/tests/integration/goldens/credentials/noxfile.py index 7d5fb2cdef..b8d69efb62 100755 --- a/tests/integration/goldens/credentials/noxfile.py +++ b/tests/integration/goldens/credentials/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/eventarc/noxfile.py b/tests/integration/goldens/eventarc/noxfile.py index ea18dc4ecb..4d16eb8942 100755 --- a/tests/integration/goldens/eventarc/noxfile.py +++ b/tests/integration/goldens/eventarc/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/logging/noxfile.py b/tests/integration/goldens/logging/noxfile.py index 9899a7348c..9b3a46d3f6 100755 --- a/tests/integration/goldens/logging/noxfile.py +++ b/tests/integration/goldens/logging/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/logging_internal/noxfile.py b/tests/integration/goldens/logging_internal/noxfile.py index 9899a7348c..9b3a46d3f6 100755 --- a/tests/integration/goldens/logging_internal/noxfile.py +++ b/tests/integration/goldens/logging_internal/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/redis/noxfile.py b/tests/integration/goldens/redis/noxfile.py index c8733082e0..788cc456f6 100755 --- a/tests/integration/goldens/redis/noxfile.py +++ b/tests/integration/goldens/redis/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/redis_selective/noxfile.py b/tests/integration/goldens/redis_selective/noxfile.py index c8733082e0..788cc456f6 100755 --- a/tests/integration/goldens/redis_selective/noxfile.py +++ b/tests/integration/goldens/redis_selective/noxfile.py @@ -89,7 +89,8 @@ def mypy(session): """Run the type checker.""" session.install( - "mypy", + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy + "mypy<1.16.0", "types-requests", "types-protobuf", ) From 67b84ec15af21b0156f94de8bc815d58bfd55670 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 17:07:09 -0700 Subject: [PATCH 7/8] Try pinning pytest-asyncio --- noxfile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8d02b33dbd..2d688e139b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -392,9 +392,9 @@ def showcase( """Run the Showcase test suite.""" with showcase_library(session, templates=templates, other_opts=other_opts): - # Exclude pytest-asyncio==1.0.0 while we investigate the recent failure described in + # Use pytest-asyncio<1.0.0 while we investigate the recent failure described in # https://github.com/googleapis/gapic-generator-python/issues/2399 - session.install("pytest", "pytest-asyncio!=1.0.0") + session.install("pytest", "pytest-asyncio<1.0.0") test_directory = Path("tests", "system") ignore_file = env.get("IGNORE_FILE") pytest_command = [ @@ -424,9 +424,9 @@ def showcase_w_rest_async( with showcase_library( session, templates=templates, other_opts=other_opts, rest_async_io_enabled=True ): - # Exclude pytest-asyncio==1.0.0 while we investigate the recent failure described in + # Use pytest-asyncio<1.0.0 while we investigate the recent failure described in # https://github.com/googleapis/gapic-generator-python/issues/2399 - session.install("pytest", "pytest-asyncio!=1.0.0") + session.install("pytest", "pytest-asyncio<1.0.0") test_directory = Path("tests", "system") ignore_file = env.get("IGNORE_FILE") pytest_command = [ From f1a1c82f6f25d07046dd48369e68c38fbe2044c9 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Wed, 27 Aug 2025 17:19:25 -0700 Subject: [PATCH 8/8] Update format --- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 32a16f55d4..92fa506b56 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -249,8 +249,7 @@ def test_{{ method_name }}_api_version_header(transport_name): with mock.patch.object( type(client.transport.{{ method.transport_safe_name|snake_case }}), '__call__'{% if mode == "async" %}, - new_callable=AsyncMock{% endif %} - ) as call: + new_callable=AsyncMock{% endif %}) as call: {% if mode == "async" %} await client.{{ method_name }}() {% else %}