[Twisted-Python] Testing with trial, adbapi questions

Christian Simms christian.simms at gmail.com
Tue Jun 26 10:27:28 EDT 2007

On 6/25/07, Brendon Colby <brendoncolby at gmail.com> wrote:
> On 6/25/07, Christian Simms <christian.simms at gmail.com> wrote:
> [snip]
> > I think you have a race condition because (I assume) self.p.lineReceived
> > indirectly 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:
> No - I'm just doing a series of runQuerys() when the server starts,
> the callbacks of which populate dictionaries with objects. The test
> sends a string identifier to the server which checks whether or not it
> exists in one of these dictionaries. When the test runs, the dict is
> empty. However, the load method IS running, just (seemingly) after the
> test is run. I guess I'm not sure how to code a test for this, as in,
> "after the database connection has been made and the data loaded, THEN
> start running tests."

Looks like I mis-assumed your problem, sorry.  In the setUp method in your
tests, you should return a Deferred which fires when all your data is
loaded.  This can be a pain if you already organized your code into classes
inheriting from twisted.application.service.Service which have
startService/stopService calls. It's a pain because trial doesn't create an
application object like running inside twistd does.  So, in the case of
writing unit tests for applications, you can abstract out your
initialization code into a method, and then call that method directly in
your setUp method.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070626/73fa62b6/attachment.htm 

More information about the Twisted-Python mailing list