Pytest segmentation fault and test fail

I am trying to run pytest tests on my PyCharm project. The test code is the following:

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

The mentioned fixture looks like this:

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

The refresh_gui method is the following:

@classmethod
def refresh_gui(cls, delay=0):
    # print('delay', delay)
    while Gtk.events_pending():
        Gtk.main_iteration_do(blocking=False)
    time.sleep(float(delay))

When I run this test as follows:

~/development/pycharm-workspace/gtkplus-tool/gtkplustool$ PYTHONPATH=~/development/pycharm-workspace/gtkplus-tool/ python -m pytest -v ~/development/pycharm-workspace/gtkplus-tool/test/

(I am adding the project root directory to the python path, to simulate the same conditions, which are present, when using the test runner in PyCharm. I read that PyCharm always adds the project root to the pythonpath.)

... I get the following output for my tests:

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

What could be the reason for this segmentation fault?

When I run this test using the PyCharm test runner, I get the following result:

  • In the list of running or executed tests the test is marked with a failed icon.
  • The terminal output does not indicate a test fail.
  • The progress bar is colored green, as if all tests ran without failing.
  • The statistics show: Test: test_XLDMainWindow.py Time elapsed: <TERMINATED>

What's more is, that pytest stops running any further tests, because of that segmentation fault, so I cannot run the other tests in a comfortable way.

Answers

I've figured it out now, but I am far from satisfied with the reason for the seg fault.

I commented the line:

Wnck.shutdown()

And the seg fault disappears. However, I am not sure now, if there is any leak or something, when I don't shut Wnck down properly. Also, this shutdown has worked before. I had the same code running a few days ago. Maybe some Ubuntu update broke something within Wnck or something.

Any further answers to why this caused a seg fault are welcome.

Posted on by Zelphir Kaltstahl