Closed Marenz closed 3 months ago
Wait, why not mock_channel = MagicMock(spec=grpc.insecure_channel) (or the base class used by all grpc channels)?
If there was a use for a proper dummy channel then it's probably better to put it in frequenz-client-base.
Your example fails for me:
def __getattr__(self, name):
if name in {'_mock_methods', '_mock_unsafe'}:
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
> raise AttributeError("Mock object has no attribute %r" % name)
E AttributeError: Mock object has no attribute 'unary_unary'
/usr/lib64/python3.11/unittest/mock.py:653: AttributeError
But it turns out all I needed is MagicMock()
and it worked. So I don't need the dummy channel after all.
added commit to make imports relative
Your example fails for me:
Oh, that's probably because of how the extremely dynamic Google's grpc is (spec=...
use introspection to also check that only symbols that exist in the mocked object are called, and with the right arguments). Another reason to use betterproto, google's stuff for python really sucks...
DummyChannel
instead of grpc one