frequenz-floss / frequenz-client-base-python

Base gRPC client
https://frequenz-floss.github.io/frequenz-client-base-python/
MIT License
0 stars 3 forks source link

Investigate and add tools to mock the grpc service to write unit tests #11

Open llucax opened 7 months ago

llucax commented 7 months ago

What's needed?

We need to be able to easily and reliably write unit tests for all API clients without having to spin up a server (real or mocked) for the tests.

Proposed solution

Add some utilities to mock the main grpc service, so we can somehow inject replies it should provide when some request is sent.

Use cases

No response

Alternatives and workarounds

Long term we could explore doing a more capable framework, [pytest-httpserver](https://pytest-httpserver.readthedocs.io/en/latest/ or even )like vcr (maybe it can be extended?) to record real responses from the server and then replay them in unit tests.

Additional context

No response

shsms commented 7 months ago

This I think is a great way to go, but not much documentation, need some trial and error to get it working: https://github.com/grpc/grpc/tree/master/src/python/grpcio_testing