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

Itamar Turner-Trauring itamar at itamarst.org
Mon Jul 16 10:06:57 EDT 2012


On 07/16/2012 09:40 AM, Dan Milstein wrote:
> To be clear: my current interest is really just doing this during unit 
> tests/ongoing development (e.g. not diagnosing prod issues, where 
> Wireshark would make plenty of sense).  So something integrated into 
> Twisted feels natural.
>
> That said, is the unit test pattern I'm seeing in the 
> mail/test/test_imap.py module atypical?  Most of the doc'd examples 
> for trial don't seem to be using loopbackTCP, so much as directly 
> writing to lineReceived or something similar.  It's only because these 
> tests are doing end-to-end things, by way of constructing both an IMAP 
> server and client, and hooking them up, that I'm in this situation.
>
twisted.test.proto_helpers.StringTransport is handy for having an 
in-memory transport you control. loopbackAsync makes it less easy to see 
the bytes, but gives you more control than loopbackTCP, since you can 
determine policies about how bytes are delivered (e.g. there's a 
one-byte-at-a-time policy IIRC).



More information about the Twisted-Python mailing list