与代码
import unittest
import time
class SleepingTest(unittest.TestCase):
def test_that_gets_stuck(self):
for a in xrange(100000000000000000):
pass
我得到这个输出
❯ nosetests use_nosetest.py
^C
----------------------------------------------------------------------
Ran 1 test in 4.267s
OK
如你所见,我用Ctrl+C来中断程序。但是鼻子说它通过了测试。我更希望它说测试失败,并给我一个堆栈跟踪。
是否有任何方法可以从我的测试卡住的地方打印堆栈跟踪?
尝试捕获Ctrl-C信号以提示进入调试器,即:
import unittest
import time
from nose.tools import set_trace
class SleepingTest(unittest.TestCase):
def test_that_gets_stuck(self):
try:
for a in xrange(10000000):
time.sleep(1)
except KeyboardInterrupt, err:
set_trace()