[zeromq-dev] Testing and debugging

andrea crotti andrea.crotti.0 at gmail.com
Tue Aug 14 16:34:51 CEST 2012

2012/8/13 Michel Pelletier <pelletier.michel at gmail.com>:
> There are generally two approaches I use in Python to test zeromq
> code.  The first is to mock the zmq library with something like
> flexmock (or one of the many other mocking libraries) and test my
> message producing/handling code in isolation.  Since the zmq api is so
> simple (bind/connect/send/recv for the most part) this is quiet easy.
> It's also a good way to do test driven development, you isolate each
> message interaction as a unit and fully test each unit.  It's also
> really fast as no actual messages get transported.
> The second level of testing is integration testing, where I use fabric
> to launch my programs (via the command line) to test their interaction
> with real messages, typically by giving them arguments of
> configurations that cause them to do things like use a test database
> or other resource instead of a live production one.  fabric is nice
> because it can ssh into machines and run remote commands to start test
> services.  I haven't tried this pattern yet, but using something like
> vagrant you can automatically spin up test virtual machines to do a
> full "cluster-wide" integration test.
> -Michel

Thanks for the help, any example of how to mock the zmq messages maybe?

I was trying to find a way and I'm ending up mocking the whole module,
but it doesn't really work this way:

class MockZmq:
    def __init__(self, content):
        """The content is what should be read on the channel
        self.content = content

    def recv(self):
        return self.content

    def send(self):

class MockContext:
    def __init__(self):
        self.socket = MockZmq()

class MockZmqModule:
    def Context():
        return MockContext()

And I'm not sure it's worth actually to mock in this way, instead I
could just send message with "inproc" instead of the TCP connections..

More information about the zeromq-dev mailing list