What's the recommended way to unittest Python GUI applications?

前端 未结 4 487
情歌与酒
情歌与酒 2021-02-02 07:01

I\'m currently foolish enough to try to maintaintain two parallel code bases for a Python desktop application, one using PyGObject introspection for GTK 3 and one using PyGTK fo

4条回答
  •  被撕碎了的回忆
    2021-02-02 07:35

    You can use a X11 framebuffer:

    Xvfb :119 -screen 0 1024x768x16 &
    export DISPLAY=:119
    ... run your tests
    

    Be sure, to not enter gtk.main(), since this would wait for mouse or keyboard input. You can use this pattern to let gtk handle all events:

    def refresh_gui():
      while gtk.events_pending():
          gtk.main_iteration_do(block=False)
    

    AFAIK you can't see your application, but you can test your callbacks.

提交回复
热议问题