Python nosetests:在Ctrl+;C
使用代码Python nosetests:在Ctrl+;C,python,stack-trace,nose,python-unittest,nosetests,Python,Stack Trace,Nose,Python Unittest,Nosetests,使用代码 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 --------------------------------------
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键中断了程序。但是nose说它可以进行测试。我很希望它说测试失败,并给我一个堆栈跟踪
是否有任何方法可以从测试卡住的位置打印堆栈跟踪?尝试使用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()
测试用例中没有失败的东西。为了获得堆栈跟踪,需要在测试开始和Ctrl+C之间的某个地方出现一些条件错误。@ILostMySpoon,ok。python开发人员如何调试他/她的程序为什么挂起在单元测试中?