[Twisted-Python] testing my application

Marcin Kasperski Marcin.Kasperski at softax.com.pl
Thu Oct 20 08:05:03 MDT 2005


Thanks for the info. Running tests vai 'trial test_x.foo' has unpleasant effect of not allowing debugging but simple trick works:
   if __name__ == "__main__":
      import twisted.scripts.trial
      import sys
      sys.argv = ['-m', 'my_test' ]
      twisted.scripts.trial.run()
(BTW, what about patching run so it could get parameters and fallback to argv only when they are not given?)

Currently I have the following problem: my test script hangs. 
Via simplification I got to the following text (requires some postgres database):

from twisted.trial import unittest
from twisted.trial.util import deferredResult
import psycopg
from twisted.enterprise import adbapi

DSN = "dbname=marcink port=5433 user=user password=pwd host=localhost"

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.dbpool = adbapi.ConnectionPool('psycopg', DSN)
        # (populating some test data)
        deferredResult( self.dbpool.runInteraction(self._insertTestData) )
    def tearDown(self):
        deferredResult( self.dbpool.runOperation("DROP TABLE mytable") );
    def _insertTestData(self, tx):
        tx.execute("CREATE TABLE mytable(id INTEGER)")
        tx.execute("INSERT INTO mytable(id) VALUES(1)")
    def testSomething(self):
        d = self.dbpool.runQuery("SELECT id FROM mytable")
        d.addCallback( lambda rows: self.assertEquals(len(rows), 1) )

When I run 
   trial -v my_test
I get
my_test
  MyTestCase
    testSomething ... 
(and the test hangs forever)




More information about the Twisted-Python mailing list