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

How to add multiple serviers?

Open scottming opened this issue 6 years ago • 2 comments
trafficstars

I have rewrite grpc_server function, It works, but not pretty.

@pytest.fixture(scope='module')
def grpc_add_to_server():
    from repo_pb2_grpc import add_RepoServiceServicer_to_server
    from file_pb2_grpc import add_FileServiceServicer_to_server
    return add_RepoServiceServicer_to_server, add_FileServiceServicer_to_server


@pytest.fixture(scope='module')
def grpc_servicer():
    from serviers.repo_servicer import RepoServicer
    from serviers.file_servicer import FileServicer
    return RepoServicer(), FileServicer()


@pytest.fixture(scope='module')
def grpc_server(_grpc_server, grpc_addr, grpc_add_to_server, grpc_servicer):
    for func, servicer in zip(grpc_add_to_server, grpc_servicer):
        func(servicer, _grpc_server)

    _grpc_server.add_insecure_port(grpc_addr)
    _grpc_server.start()
    yield _grpc_server
    _grpc_server.stop(grace=None)

scottming avatar Mar 24 '19 09:03 scottming

Yep, looks ugly. I'm going to look something about this case.

kataev avatar Mar 27 '19 18:03 kataev

Interested to see how we can add multiple services as well.

With the above example, how should we handle this method?

def grpc_stub_cls(grpc_channel):
   ...

ddavtian avatar May 15 '21 16:05 ddavtian

Did anyone figure out the answer?

mohitjestepeloton avatar May 02 '23 15:05 mohitjestepeloton

Also interested in this feature, would be good to integrate a better way to do this.

abdellahrami avatar May 02 '23 17:05 abdellahrami