Skip to content

Commit 44b4880

Browse files
committed
fix (and cover with test) the case
1 parent 486cef3 commit 44b4880

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nipype/utils/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,16 @@ def _mock():
202202
Xvfb = namedtuple('Xvfb', ['vdisplay_num', 'stop'])
203203
self._display = Xvfb(ndisp, _mock)
204204
return sysdisplay
205-
206205
else:
206+
# If $DISPLAY is empty, it confuses Xvfb so unset
207+
if sysdisplay == '':
208+
del os.environ['DISPLAY']
207209
try:
208210
from xvfbwrapper import Xvfb
209211
except ImportError:
210212
raise RuntimeError(
211213
'A display server was required, but $DISPLAY is not defined '
212-
' and Xvfb could not be imported.')
214+
'and Xvfb could not be imported.')
213215

214216
self._display = Xvfb(nolisten='tcp')
215217
self._display.start()

nipype/utils/tests/test_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ def test_display_noconfig_nosystem(monkeypatch):
3838
if config.has_option('execution', 'display_variable'):
3939
config._config.remove_option('execution', 'display_variable')
4040
monkeypatch.delitem(os.environ, 'DISPLAY', raising=False)
41-
assert int(config.get_display().split(':')[-1]) > 80
41+
assert int(config.get_display().split(':')[-1]) > 80
42+
43+
def test_display_empty(monkeypatch):
44+
"""Check that when no display is specified, a virtual Xvfb is used"""
45+
config._display = None
46+
if config.has_option('execution', 'display_variable'):
47+
config._config.remove_option('execution', 'display_variable')
48+
monkeypatch.setitem(os.environ, 'DISPLAY', '')
49+
assert int(config.get_display().split(':')[-1]) > 80

0 commit comments

Comments
 (0)