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:
        if window.has_name():
            if window.get_name() == self.xld_main_window.get_title():
                window_found = True
    assert window_found, 'The Gtk.Window named {window_name} has not been found.'\

    # clean up Wnck (saves resources, check documentation)
    del window
    del screen

The mentioned fixture looks like this:

def create_xld_main_window(self):
    self.xld_main_window = XLDMainWindow()

The refresh_gui method is the following:

def refresh_gui(cls, delay=0):
    # print('delay', delay)
    while Gtk.events_pending():

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/ PASSED
../test/example/ PASSED
../test/gui/ 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: 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.


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

I commented the line:


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