Plotting on continuous integration systems such as Travis CI, AppVeyor, GitLab, etc. can be tricky, since in many cases the CI doesn’t have an X11 display server. Workaround include:
- Pytest conditional tests that detect CI via environment variable, totally avoiding generating plots
- generate plots using
xvfbdummy X11 display server
Add to your
Detect CI inside Python
Pytest handles conditional tests well.
import os import pytest CI = os.environ.get('CI') in ('True', 'true') @pytest.mark.skipif(CI, reason="no plots for CI") def test_myfun(): from matplotlib.pyplot import figure,show ...
- Travis-CI update enabling Xvfb
CI Environment variables
These CI’s and more set the environment variable
CI as a de facto standard for easy CI detection.
Here are a few listings of CI system environment variables for reference: