![](https://secure.gravatar.com/avatar/f9b3b8f946adb12579b22425a2f29d7d.jpg?s=120&d=mm&r=g)
On 6/25/07, Brendon Colby <brendoncolby@gmail.com> wrote:
On 6/25/07, Christian Simms <christian.simms@gmail.com> wrote:
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
[snip] 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."
[snip]
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. Cheers, Christian