astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
199 stars 109 forks source link

astroplan test failure (scientific linux, py2.7.10) #110

Closed bmorris3 closed 8 years ago

bmorris3 commented 9 years ago
=================================== FAILURES ===================================
______________________________ test_image_example ______________________________

    @pytest.mark.skipif('not HAS_MATPLOTLIB')
    @pytest.mark.mpl_image_compare
    def test_image_example():
        import matplotlib.pyplot as plt
>       fig = plt.figure()

...

 print("Starting up QApplication")
            app = QtWidgets.QApplication.instance()
            if app is None:
                # check for DISPLAY env variable on X11 build of Qt
                if hasattr(QtGui, "QX11Info"):
                    display = os.environ.get('DISPLAY')
                    if display is None or not re.search(':\d', display):
>                       raise RuntimeError('Invalid DISPLAY variable')
E                       RuntimeError: Invalid DISPLAY variable

../../apps6/anaconda2.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py:138: RuntimeError
=============== 1 failed, 43 passed, 1 skipped in 52.98 seconds ================

Any ideas @cdeil @jberlanga @eteq?

cdeil commented 9 years ago

This is not an astroplan-specific issue. The tests for other Astropy-affiliated packages fail or even crash if DISPLAY isn't configured correctly and a matplotlib plot is made.

The solution is to set DISPLAY e.g. like this https://github.com/astrofrog/wcsaxes/blob/master/.travis.yml#L75

    # Make sure that interactive matplotlib backends work
    - export DISPLAY=:99.0
    - sh -e /etc/init.d/xvfb start
    # Make sure matplotlib uses PyQT not PySide
    - export QT_API=pyqt

Maybe @mdboom or @astrofrog can comment if there is something in the Astropy test runner that can automatically handle this? Or maybe this is just something that should be documented for users / contributors, e.g. here? http://astropy.readthedocs.org/en/latest/known_issues.html#build-installation-test-issues

astrofrog commented 9 years ago

The fix @cdeil points out is the correct one. The issue is that really matplotlib should default to non-interactive Agg, but not quite sure why it doesn't when we run tests.

cdeil commented 9 years ago

@astrofrog I just thought of something ... can't we just add

import matplotlib
matplotlib.use('agg')

in the pytest setup (e.g. here: https://github.com/astropy/astroplan/blob/master/astroplan/conftest.py#L34) so that matplotlib tests for all users run with a non-interactive matplotlib backend? No more fiddling with DISPLAY or pop-up windows when running the tests.

astrofrog commented 9 years ago

@cdeil - I tried that before, but had issues with it related to the fact pytest imports the module before running its setup. In other words, astroplan has to be imported before conftest.py is. If importing astroplan causes matplotlib to be imported, then it won't work. But otherwise it's worth the try.

bmorris3 commented 8 years ago

No longer an issue, and as @cdeil points out, probably not an astroplan issue.