I'm having trouble to get twisted's unittesting working on a simple code (see
bellow)
the problem is that when running the code by doing 'trial code.py' only the
main function is being called,
but the deferred functions are being ignored ( i see in the output 'f()' but
not '_f()' and a file isn't created)
running the code straight from the shell behaves normally (python code.py)
I'm using an updated version of twisted (from the svn) but the same thing
happens also in previous versions (I have also a version from a year ago).
any ideas?
P.S.
from what I gathered, I don't need to use reactor.callLater inside unittests
since the trial program loads a reactor by itself.
Thanks,
Ido.
================= code.py =========================
from twisted.internet import threads
from twisted.trial import unittest
import logging, time
class C(object):
def _f(self):
logging.info('_f')
open('/tmp/_f.txt','w').close()
return 4+5
def _f_succ_handler(self, result):
logging.info('_f_succ_handler: %s' % result)
pass
def _f_err_handler(self, error):
logging.info('_f_err_handler: %s' % error)
def f(self):
logging.debug('f()')
d = threads.deferToThread(self._f)
d.addCallback(self._f_succ_handler)
d.addErrback(self._f_err_handler)
return d
class TestC(unittest.TestCase):
def setUp(self):
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
)
def testTemp(self):
c = C()
d = c.f()
logging.debug(d)
time.sleep(10)
if __name__ == '__main__':
from twisted.internet import reactor
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
)
c = C()
reactor.callLater(0.1, c.f)
reactor.run()
=================================
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il