nosetests:在Ctrl+C上获取堆栈跟踪

2024-09-26 22:42:04 发布

您现在位置:Python中文网/ 问答频道 /正文

有了密码

import unittest
import time

class SleepingTest(unittest.TestCase):

    def test_that_gets_stuck(self):
        for a in xrange(100000000000000000):
            pass

我得到这个输出

^{pr2}$

如您所见,我使用Ctrl+C来中断程序。但是鼻子说它的测试正常。我更希望它能说测试失败了并给我一个堆栈跟踪。在

有什么方法可以打印出测试卡住的堆栈跟踪吗?在


Tags: testimportself密码forthattime堆栈
1条回答
网友
1楼 · 发布于 2024-09-26 22:42:04

{a1,尝试进入调试器的信号

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()

相关问题 更多 >

    热门问题