diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index 6408f306dc..d8b637b332 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] = [] @@ -81,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/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..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 @@ -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,8 +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__' - ) as call: + '__call__'{% if mode == "async" %}, + new_callable=AsyncMock{% endif %}) as call: {% if mode == "async" %} await client.{{ method_name }}() {% else %} diff --git a/noxfile.py b/noxfile.py index 7b686cb7db..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 = [ @@ -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", diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index 4efb1b1161..cd82d70fc3 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] = [] @@ -88,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 3aea2c0c1b..b8d69efb62 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] = [] @@ -88,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 ba8fbf5fc2..4d16eb8942 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] = [] @@ -88,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 2e9dd52f17..9b3a46d3f6 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] = [] @@ -88,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 2e9dd52f17..9b3a46d3f6 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] = [] @@ -88,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 5768044661..788cc456f6 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] = [] @@ -88,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 5768044661..788cc456f6 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] = [] @@ -88,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", )