Testing
You can use generated stubs to test your services. But it is not needed to setup connectivity over network interfaces. grpclib provides ability to use real client-side code, real server-side code, and real h2/gRPC protocol to test your services, with all the data sent in-memory.
Reference
- class grpclib.testing.ChannelFor(services: Collection[IServable], codec: Optional[CodecBase] = None, status_details_codec: Optional[StatusDetailsCodecBase] = None)
Manages specially initialised
Channel
with an in-memory transport to aServer
Example:
class Greeter(GreeterBase): ... greeter = Greeter() async with ChannelFor([greeter]) as channel: stub = GreeterStub(channel) response = await stub.SayHello(HelloRequest(name='Dr. Strange')) assert response.message == 'Hello, Dr. Strange!'
- Parameters
services – list of services you want to test
codec – instance of a codec to encode and decode messages, if omitted
ProtoCodec
is used by defaultstatus_details_codec – instance of a status details codec to encode and decode error details in a trailing metadata, if omitted
ProtoStatusDetailsCodec
is used by default