【发布时间】:2021-03-31 22:04:10
【问题描述】:
按照this question 中的建议,我能够使用grpc_testing 库对我的gRPC 服务(使用grpc.aio API 构建)的同步方法进行单元测试。但是,当我在我的 gRPC 服务的异步方法上关注 this example 时,我得到:
ERROR grpc_testing._server._rpc:_rpc.py:92 Exception calling application!
Traceback (most recent call last):
File "/home/jp/venvs/grpc/lib/python3.8/site-packages/grpc_testing/_server/_service.py", line 63, in _stream_response
response = copy.deepcopy(next(response_iterator))
TypeError: 'async_generator' object is not an iterator
查看grpc_testing 代码库并进行更广泛的搜索,我找不到单元测试异步 gRPC 方法的示例。我能找到的最接近的东西是pytest-grpc 的unmerged branch,但the example service 没有任何异步方法。
谁能分享一个在 python 中对异步 gRPC 方法进行单元测试的示例?
【问题讨论】:
-
我用最简单的设置想出了答案How to do unit tests on python async functions?
标签: grpc-python