It’s useful to not plot on Travis-CI in most cases, because Travis doesn’t have an X11 desktop. There are two main ways to accompish this:
ifstatement(s) in the Python code, totally avoiding generating plots
- generate plots, but use
xvfbdummy X11 desktop
xvfb method is a more complete test of your code and is easier to implement.
This method is more robust and recommended.
Add to your
# Fake X11 server before_script: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 # give xvfb some time to start
Detect Travis-CI inside Python
Put self-test Python code that plots AND the
matplotlib import under this
import os def test_myfun(): if not 'TRAVIS' in os.environ or not os.environ['TRAVIS']: from matplotlib.pyplot import figure,show ... disabled plotting code on Travis CI
- Travis-CI environment variables