Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 2612994

Browse files
committed
fix: import and use asyncio for async service test
1 parent c9c58b5 commit 2612994

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

gapic/templates/noxfile.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12",
5555
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
5656
"mock",
5757
"pytest",
58+
"pytest-asyncio"
5859
"google-cloud-testutils",
5960
]
6061
SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = []

gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def test__get_api_endpoint():
226226
{% for method in service.methods.values() %}{% with method_name = method.name|snake_case %}
227227
{% for mode in ["", "async"] %}
228228
{% if mode == "async" %}
229+
@pytest.mark.asyncio
229230
async def test_{{ method_name }}_api_version_header_async(transport_name="grpc"):
230231
client = {{ service.async_client_name }}(credentials=async_anonymous_credentials(), transport=transport_name)
231232
{% else %}
@@ -247,7 +248,8 @@ def test_{{ method_name }}_api_version_header(transport_name):
247248
# Mock the actual call within the gRPC stub, and fake the request.
248249
with mock.patch.object(
249250
type(client.transport.{{ method.transport_safe_name|snake_case }}),
250-
'__call__'
251+
'__call__'{% if mode == "async" %},
252+
new_callable=AsyncMock{% endif %}
251253
) as call:
252254
{% if mode == "async" %}
253255
await client.{{ method_name }}()

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def fragment(session, use_ads_templates=False):
167167
"pytest-cov",
168168
"pytest-xdist",
169169
"asyncmock; python_version < '3.8'",
170-
"pytest-asyncio < '1.1.0'",
170+
"pytest-asyncio<1.1.0",
171171
"grpcio-tools",
172172
)
173173
session.install("-e", ".")
@@ -480,7 +480,7 @@ def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False
480480
"pytest-cov",
481481
"pytest-xdist",
482482
"asyncmock; python_version < '3.8'",
483-
"pytest-asyncio < '1.1.0'",
483+
"pytest-asyncio<1.1.0",
484484
)
485485
# Run the tests.
486486
# NOTE: async rest is not supported against the minimum supported version of google-api-core.

0 commit comments

Comments
 (0)