我正在運行一個單元測試,並且我意識到拋出了一個異常。但是,我只是不確定到底拋出了什麼。Python:看不到拋出的異常
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()
的PathPicker類:
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
我試過了。沒有什麼改變。奇怪的。另外,檢查編輯。 – BUInvent
噢,QtWidget初始化中發生了一些奇怪的事情,並且它決定停止執行程序:'( –
@SlakNation回答編輯了新信息 –