0
我試圖在我的PyCharm project
上運行pytest
測試。測試代碼是下面的:Pytest分段錯誤和測試失敗
def test_window_created(self, create_xld_main_window):
"""This test tests, whether or not the Gtk.Window has been created.
"""
screen = Wnck.Screen.get_default()
screen.force_update() # recommended per Wnck documentation
window_list = screen.get_windows()
for window in window_list:
print(window.get_name())
if window.has_name():
if window.get_name() == self.xld_main_window.get_title():
window_found = True
break
assert window_found, 'The Gtk.Window named {window_name} has not been found.'\
.format(window_name=self.xld_main_window.get_title())
# clean up Wnck (saves resources, check documentation)
del window
del screen
Wnck.shutdown()
所提到的固定裝置是這樣的:
@pytest.fixture()
def create_xld_main_window(self):
AppSettings.load_settings()
VocableManager.load_vocables()
self.xld_main_window = XLDMainWindow()
self.xld_main_window.show_all()
GTKGUITestHelper.refresh_gui()
的refresh_gui
方法如下:
@classmethod
def refresh_gui(cls, delay=0):
# print('delay', delay)
while Gtk.events_pending():
Gtk.main_iteration_do(blocking=False)
time.sleep(float(delay))
當運行該測試如下:
~/development/pycharm-workspace/gtkplus-tool/gtkplustool$ PYTHONPATH=~/development/pycharm-workspace/gtkplus-tool/ python -m pytest -v ~/development/pycharm-workspace/gtkplus-tool/test/
(我將項目根目錄添加到python路徑中,以模擬PyCharm中使用測試運行器時出現的相同條件。我讀了PyCharm總是添加項目根到PYTHONPATH)
...我得到以下輸出爲我的測試:
================================================= test session starts ==================================================
platform linux -- Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2 -- /home/xiaolong/development/anaconda3/envs/gtkplus-tool/bin/python
rootdir: /home/xiaolong/development/pycharm-workspace/gtkplus-tool/test, inifile:
collected 6 items
../test/example/example_gui_unit_test.py::MyViewTest::test_count PASSED
../test/example/example_gui_unit_test.py::MyViewTest::test_label PASSED
../test/gui/test_XLDMainWindow.py::TestXLDMainWindow::test_window_created Segmentation fault (core dumped)
有什麼能爲這個段錯誤的原因是什麼?
當我運行使用PyCharm測試運行這個測試,我得到以下結果:
- 運行列表或執行測試的測試標有失敗的圖標。
- 終端輸出不表示測試失敗。
- 進度條顯示爲綠色,就好像所有測試都沒有失敗一樣。
- 的統計數據顯示:
Test: test_XLDMainWindow.py Time elapsed: <TERMINATED>
更重要的是,pytest停止運行,因爲分段故障的任何進一步的測試,所以我不能運行在一個舒適的方式在其他測試。