[Twisted-Python] How to best log server/client interactions from a test?

Dan Milstein dan at wingu.com
Thu Jul 12 16:31:09 EDT 2012

'lo all,

I've been doing some work with the twisted.mail.imap4 module, and its associated unit tests (in order to learn the code more, I'm tackling a few of the outstanding tickets).

When running those tests, I'd often like to log all the server/client interaction.  I managed to do so by way of hacking the code in twisted.protocols.loopback, but that feels pretty wrong.  What's a good way to get all the interaction logged?

To be more specific, the tests in question (e.g. test_imap.NewFetchTestCase), do a lot of:

    d = loopback.loopbackTCP(self.server, self.client, noisy=False)
    d.addCallback(lambda x : self.assertEqual(self.result, self.expected))
    return d

What's a Good Way to get all the traffic going over that loopback logged?  Setting noisy to True merely gets it to log some protocol startup/teardown-type messages.  

Or: given that I've figured out how to hack loopback.lookupbackTCP, if there's general utility, I can certainly add a keyword arg to trigger logging of all messages, e.g. logAll=False (I'm trying to find something which feels meaningfully different from 'noisy', because it would seem Very Wrong Indeed to make noisy suddenly produce vastly more log output).  Is that something people might be interested in?


More information about the Twisted-Python mailing list