[Twisted-Python] Testing with trial, adbapi questions

Jean-Paul Calderone exarkun at divmod.com
Mon Jun 25 12:49:00 EDT 2007

On Mon, 25 Jun 2007 12:28:23 -0400, Christian Simms <christian.simms at gmail.com> wrote:
> [snip]
>I think you have a race condition because (I assume)
>self.p.lineReceivedindirectly did a database insert, and then the
>self.check did a database select.  If that's true, you should make your test
>use Deferred's like this:
>  d = defer.succeed(None)
>  d.addCallback(lambda out: self.p.lineReceived('{%s:"PG"}\0' %
>  d.addCallback(lambda out: self.check("test\0"))
>  return d
>You could also write this code using the new defer.inlineCallbacks (needs
>python 2.5) or the older defer.deferredGenerator, but you might as well get
>used to using callbacks/errbacks and Deferred's.

Note that the above requires lineReceived to return a Deferred which only
fires after the insert has completed and check to return a Deferred which
represents the result of the select (if those are indeed the underlying


More information about the Twisted-Python mailing list