pytest-grpc
pytest-grpc copied to clipboard
Example needed on asserting StatusCodes
If I'm expecting a service to fail a request with a specific status code I'd like to assert that the correct StatusCode is returned by grpc.
After much digging here's a working example:
def test_GetUser(grpc_stub):
request = GetUserRequest()
with pytest.raises(grpc.RpcError) as e:
response = grpc_stub.GetUser(request)
assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT