1

我们的 Python 代码库使用nose 来运行所有单元测试,我正在尝试使用nose.twistedtools 来让所有测试运行,但它们都在关机时挂起。任何帮助解决这个问题都会很棒。这是一个挂起的简单测试:

from nose.twistedtools import deferred
from twisted.internet.defer import Deferred

@deferred(timeout=1)
def test_rudimentary():
    def done(_ignored):
        print "DONE"

    defer = Deferred()
    defer.addCallback(done)
    return defer

调用和输出如下所示:

$ nosetests test_simple.py 
F
======================================================================
FAIL: test_simple.test_rudimentary
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/<ENV>/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/<ENV>/lib/python2.7/site-packages/nose/twistedtools.py", line 165, in wrapper
    % timeout)
TimeExpired: timeout expired before end of test (1.000000 s.)

----------------------------------------------------------------------
Ran 1 test in 1.001s

FAILED (failures=1)

如果我不设置超时,测试将永远挂起。

4

1 回答 1

2

您的代码负责调用 defer.callback/errback(很可能是间接调用)。尝试:

reactor.callLater(0.1, defer.callback)
return defer
于 2012-10-09T21:02:18.207 回答