Skip to content

Example needed on asserting StatusCodes #9

@jinnatar

Description

@jinnatar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions