Reputation: 18264
I have a unit test which contains
import gtk
Which contains unit tests to test the signal handler and GUI classes. This works fine when I run py.test
from the shell as I have an X11 display connected. However, when I try to run tox, I get:
______________________ ERROR collecting tests/test_gui.py ______________________
tests/test_gui.py:17: in <module>
from rprs_bootstrap.gui import GUI
src/gui.py:12: in <module>
import gtk.glade
.tox/py27/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:64: in <module>
_init()
.tox/py27/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:52: in _init
_gtk.init_check()
E RuntimeError: could not open display
!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.34 seconds ============================
make: *** [tox] Error 2
I could start a Xvfb server from within tox.ini
but that seems inelegant. Any suggestions?
Upvotes: 3
Views: 3033
Reputation: 18264
Use pytest-xvfb
which
[...] runs your testsuite with Xvfb to avoid popping up windows during GUI tests or allow them to run on systems without a display (like a CI).
To install:
pip install pytest-xvfb
Upvotes: 2