[Twisted-Python] deferToThread and trial

Dustin J. Mitchell dustin at v.igoro.us
Fri May 30 06:43:58 MDT 2014


On Fri, May 30, 2014 at 2:13 AM, Piper Masden <piper.masden at gmail.com> wrote:
> I have a test that executes this function, and the deferToThread returns a
> Deferred, but that deferred never fires its callback, and so when I use
> successResultOf expecting a success result, no result is found.

"Never", or just not before you check its result?  I don't think
successResultOf blocks waiting for the Deferred to fire.

Instead, you need to wait for the deferred within your test:

def testIndex(self):
  d = index(..)
  @d.addCallback
  def check(result):
      self.assertEqual(result, ..)
  return d

(this could be prettier with inlineCallbacks, but this should give you the idea)

Dustin



More information about the Twisted-Python mailing list