From @muzzi92 on Fri Jul 13 2018 11:19:03 GMT+0000 (UTC)
I’m brand new to Nameko but I have encountered an issue whilst trying to unit test my service.
I am using pytest, and I was hoping to create a worker so that I can test whether my dependency’s function was called inside my service’s function.
However, before getting to that stage, I was doing provisional tests on my newly created worker to check that its dependencies had been mocked with MagicMock. It is at this point it tells me the dependency is not an instance of Mock, and hence I cannot move on to setting side_effects or asserting calls.
Am I missing something that allows worker dependencies to be mocked?
Any tips for testing Nameko are greatly appreciated.
from payment_service import SecondService from nameko.events import event_handler from foobar import FooBar class FirstService(object): name = 'first_service' dependency = FooBar() @event_handler('second_service', 'complete') def foo(self, payload): self.dependency.bar(param)
from first_service import FirstService from nameko.testing.services import worker_factory from unittest.mock import Mock class TestFirstService(object): def test_foo(self): service = worker_factory(FirstService) assert isinstance(service, FirstService) #passes assert isinstance(service.dependency, Mock) #fails ```<br /><br /><i>Copied from original issue: https://github.com/nameko/nameko/issues/555</i>