[Twisted-Python] Writing unit tests with Trial for Twisted Applications

Jp Calderone exarkun at intarweb.us
Wed Oct 1 23:38:10 EDT 2003

On Thu, Oct 02, 2003 at 12:53:14PM +1000, Andrew Bennetts wrote:
> On Wed, Oct 01, 2003 at 10:44:05PM -0400, Christopher Armstrong wrote:
> [snip]
> > you do test over the network, make sure you listen on a local-only
> > interface (i.e., '') and use a portno of 0. e.g.:
> > 
> >         self.port = reactor.listenTCP(0, self.svr, interface="")
> >         self.portno = self.port.getHost()[-1]
> This bothers me a little; the details of TCP connections are generally
> irrelevant to what the test method is trying to test (and TCP, hopefully, is
> getting fully tested in test_tcp).  It'd be nice if this wasn't required.

  I agree.  Only a few of the tests you write should actually go over the
network -- note that loopback.loopback() and the rest of the fake transport
bit fall into this category!).  The bulk of your functionality should be
testable in isolation of the network code.  If it's not, consider trying to
rewrite it so it is.  This will lead to simpler, more reliable tests as well
as simpler and more modular code.


"The problem is, of course, that not only is economics bankrupt but it has
 always been nothing more than politics in disguise ... economics is a form
 of brain damage."  -- Hazel Henderson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20031001/3e857d6a/attachment.pgp 

More information about the Twisted-Python mailing list