I have a package that has a module that helps users generate specific plots using matplotlib. When I call these functions in my unit tests inside Travis, I get the following error:
RuntimeError: Invalid DISPLAY variable
How do I fix that?
After generating the plot, my functions usually call pyplot.show()
, which opens a window that needs to be closed. When I call these functions in my unit tests inside Travis, they get hung up forever.
How do I test that these plots are being generated using Travis CI?
You can solve this without explicitly setting display by using the "agg" backend in matplotlib. This is necessary anyway, in my experience, in order to ensure consistency of the generated images. Just make sure you
matplotlib.use('agg')
before you import pyplot or pylab. I've explained more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With