【发布时间】:2015-11-30 17:00:42
【问题描述】:
我正在尝试在我的 PyCharm project 上运行 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 停止运行任何进一步的测试,所以我无法以舒适的方式运行其他测试。
【问题讨论】:
标签: python unit-testing segmentation-fault pycharm pytest