Unit-testing a Nameko microservice
According to the documentation, http://url.marcuspen.com/nameko, Nameko is:
"A microservices framework for Python that lets service developers concentrate on application logic and encourages testability."
We will now focus on the testability part of Nameko; it provides some very useful tools for isolating and testing its services.
Create a new folder, tests
, and place two new files inside, __init__.py
(which can be left blank) and test_service.py
:
from nameko.testing.services import worker_factory from temp_messenger.service import KonnichiwaService def test_konnichiwa(): service = worker_factory(KonnichiwaService) result = service.konnichiwa() assert result == 'Konnichiwa!'
When running outside of the test environment, Nameko spawns a new worker for each entrypoint that is called. Earlier, when we tested our konnichiwa
RPC, the Konnichiwa Service would have been listening for new messages on the Rabbit queue. Once it received a new message...