Well, I finally solved this problem. And it was actually not a problem in Gtk. 
I was prejudiced that it was caused by Gtk_main() not exited properly or 
main_window not destroyed properly and stuck waiting for events (as described 
in the previous answer), but it was not the actual problem and now it works.

The problem was in run_window.py > RunLoggingHandler > emit() > 
Gdk.threads_enter() <- it froze here. The 'logger' variable in logger.py was 
global and when a RunLoggingHandler was added into it 
("logger.addHandler(self.tlh)" in run_window.py), it retained here and when 
emit() was called in following tests, it stuck here. Fixed it by clearing 
logger handlers after the tests:

from devassistant.logger import logger

def teardown_method(self, method): 
    logger.handlers = []


----- Original Message -----
From: "Jaromir Koncicky" <jkonc...@redhat.com>
To: python-hackers-list@gnome.org
Sent: Friday, March 28, 2014 3:17:05 PM
Subject: Testing GUI application using pygobject3 with pytest problem

(Please note I already posted this question at Stack Overflow: 
https://stackoverflow.com/questions/22715241/testing-gui-application-using-pygobject3-with-pytest
 )

I got a task to write some unit tests for devassistant (a helper program can 
help you set up your developing environment). It is written in Python and 
offers graphical user interface which is implemented with pygobject3. There are 
already unit tests, using pytest.
I wrote some basic tests, which work like this:

- create the main window (like the application was executed normally by a 
human) but do not call Gtk.main() - so that the main window won't show up
- simulate interactions with gui (clicking buttons, un/tinking checkboxes etc) 
or directly call their callbacks
- check if things are as expected (call asserts)

The actual problem is, that when the gui tests are passed and there are more 
tests after the gui tests, during doing the following tests an empty window 
(with just a title) shows up and pytest freezes (the empty window does't react 
and cannot be closed), so I must kill it. If I "move" the gui tests to the last 
position, they work normally.

Steps to reproduce:

- clone my repository https://github.com/jkoncick/devassistant - the actual 
commit adding the tests is 
https://github.com/jkoncick/devassistant/commit/e4296fcf7e1393a1140f3205304e54b9e8c62375
- (install all required python packages - they are in the requirements file)
- move the test_gui.py file into parent directory - so that the gui tests are 
not performed last but there are some tests after them
- in devassistant/gui/main_window.py delete line 81 with "self.main_win.hide()"
- run tests with "./setup.py test"
- after doing gui tests (they should pass) an empty window shows up and pytest 
freezes. If you do not delete the line "self.main_win.hide()", the window won't 
show but pytest freezes anyway

I am really helpless with it. Moving the gui test to be last works, but it is 
rather a workaround and I cannot assume it will work everywhere. I could not 
manage to "close" or "destroy" the main window so that it wouldn't show up and 
break the tests.
I tried these, but none worked:

app.main_win.destroy()
app.main_win.emit('delete-event', None)
Gtk.main_quit()

Do you please have any idea how to solve this?


_______________________________________________
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list
_______________________________________________
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list

Reply via email to