pytest-grpc icon indicating copy to clipboard operation
pytest-grpc copied to clipboard

Example needed on asserting StatusCodes

Open jinnatar opened this issue 6 years ago • 0 comments

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

jinnatar avatar Sep 03 '19 18:09 jinnatar