我正在运行单元测试,我意识到抛出了异常。然而,我只是不确定到底抛出了什么。
from pt_hil.utilities.PT_HIL_Interface_Utils.widgets import PathPicker
import unittest
import wx
class TestUM(unittest.TestCase):
@classmethod
def setUpClass(cls):
print 'setUpClass called'
cls.path_picker = PathPicker()
print 'path_picker has been declared'
def test_PathPicker(self):
self.assertRaises(NotImplementedError, wx.UIActionSimulator.MouseClick(self.path_picker.browse))
if __name__ == '__main__':
unittest.main()
路径选择器类:
class PathPicker(Widget):
def __init__(self, parent=None, name="PathPicker"):
print 'hi1'
try:
Widget.__init__(self, name, parent)
except Exception as e:
print 'hello'
return logging.error(traceback.format_exc())
print 'hi2'
运行单元测试时得到的输出是:
setUpClass called
hi1
Process finished with exit code 1
很明显,出现问题的地方是:Widget.__init__(self, name, parent)
但我看不出它是什么。有什么方法可以让我打印出抛出的异常或错误吗?
编辑:这是与之配套的 Widget 类:
class Widget(QWidget):
def __init__(self, name, parent=None):
print 'hey2'
try:
super(Widget, self).__init__()
except BaseException as e:
print 'hello'
return logging.error(traceback.format_exc())
print 'hey3'
现在它给了我:
setUpClass called
hi1
hey2
Process finished with exit code 1