ericmandel / pyds9

Python connection to SAOimage DS9 via XPA
76 stars 41 forks source link

Should the tests skip if $DISPLAY is not set up #91

Open DougBurke opened 4 years ago

DougBurke commented 4 years ago

Running python setup.py test -a -v on a remote macOS system which doesn't have X forwarding set up causes the tests to hang when it gets to the "can you start ds9 and communicate with it" tests. I assume this is what caused some of the recent test "failures" when they would time out (as they seemed to be timing out at this point).

If I control-c I get info (from tcl/tk?) that the display is borked - e.g.

pyds9/tests/test_pyds9.py::test_ds9_targets_empty PASSED                 [ 41%]
pyds9/tests/test_pyds9.py::test_ds9_targets ^Capplication-specific initialization failed: no display name and no $DISPLAY environment variable
application-specific initialization failed: no display name and no $DISPLAY environment variable
Unable to initialize window system.
Unable to initialize window system.
application-specific initialization failed: no display name and no $DISPLAY environment variable
Unable to initialize window system.

Something like the (untested)

import os

display_not_set = 'DISPLAY' not in os.environ

@pytest.mark.skipif(display_not_set, reason='No DISPLAY environment variable!')
DougBurke commented 4 years ago

I'm not sure why the tests hang (or appear to) since this fails fairly quickly:

%  DISPLAY=:2000 python -c 'import pyds9; print(pyds9.__version__); pyds9.DS9().get("fits");'
1.9.dev244
application-specific initialization failed: couldn't connect to display ":2000"
Unable to initialize window system.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dburke/ciao/pyds9/pyds9/pyds9.py", line 493, in __init__
    raise ValueError('no active ds9 running for target: %s' % target)
ValueError: no active ds9 running for target: ds9

I've also tried with unset DISPLAY and with/without XPA_METHOD=local and see the behavior (i.e. it errors out rather than appearing to hang). Presumably something in the test setup?

ericmandel commented 4 years ago

Depending on how the system is configured, an inet connect() call will hang instead of erroring for about 30 seconds, until it times out. We see this problem on Macs especially. I think (but I can't quite recall) the hang might be related to turning on stealth mode in the Mac firewall ...

DougBurke commented 4 years ago

I see it on linux - using

% unset DISPLAY
% python setup.py test -a --full-trace

and then control-c when its obviously "hung" shows me it's the way the test is set up:

    @contextlib.contextmanager
    def _run_ds9s(*names):
        processes = []
        for name in names:
            cmd = ['ds9', '-title', name]
            processes.append(sp.Popen(cmd))
        # wait for all the ds9 to come alive
        while True:
            targets = pyds9.ds9_targets()
            if targets and len(targets) == len(processes):
                break
>           time.sleep(0.1)
E           KeyboardInterrupt

This is never going to finish if there's no viable display! Perhaps the Popen should be changed to something that will check for ds9 running successfully?

Not a high priority item.