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

Glyph glyph at twistedmatrix.com
Mon Jul 16 13:34:16 EDT 2012

Le Jul 16, 2012 à 6:40 AM, Dan Milstein <dan at wingu.com> a écrit :

> 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.

Sorry, you're quite right that I misunderstood your question.

As Jean-Paul already said, this test code is quite old.

If you want to be diagnosing what's going on in a test, writing a (temporary) IProtocol or ITransport wrapper that has some print statements in it can be a good way to go.  Or as Itamar suggested, using StringTransport() and printing its contents.  Definitely using StringTransport would be preferred for anything you'd actually want to keep around in a test if you want to assert about what's being read or written, and not just look at a dump of the output.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120716/60aa81e8/attachment.htm 

More information about the Twisted-Python mailing list