1

I am trying to run tests on software that uses ursina, a python gaming engine. When importing ursina no graphical device is found and the pipeline fails with an error. Is there a standard mitigation for such scenarios, i.e. a standard way to "mock" a screen in a GitLab pipeline?

My current GitLab pipeline looks something like this:

image: python:latest

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

cache:
  paths:
    - .cache/pip
    - env/

before_script:
  - pip install virtualenv
  - virtualenv env
  - source venv/bin/activate
  - pip install -r requirements.txt

test:
  script:
    - python ...

The error I get when running tests on files where ursina is imported is:

======================================================================
ERROR: foobar.test.test_foobar (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: foobar.test.test_foobar
Traceback (most recent call last):
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/unix_connect.py", line 105, in get_socket
    s = _get_unix_socket(address)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/unix_connect.py", line 84, in _get_unix_socket
    s.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/unix_connect.py", line 109, in get_socket
    s = _get_tcp_socket(host, dno)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/unix_connect.py", line 79, in _get_tcp_socket
    s.connect((host, 6000 + dno))
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/ursina/window.py", line 50, in __init__
    resolution = Xlib.display.Display().screen().root.get_geometry()
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/protocol/display.py", line 90, in __init__
    self.socket = connect.get_socket(name, protocol, host, displayno)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/connect.py", line 87, in get_socket
    return mod.get_socket(dname, protocol, host, dno)
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/Xlib/support/unix_connect.py", line 113, in get_socket
    raise error.DisplayConnectionError(dname, str(val))
Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/lib/python3/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/builds/johndoe/foo/foobar/test/test_foobar.py", line 4, in <module>
    from foobar.src.foobar import foobar
  File "/builds/johndoe/foo/foobar/src/foobar.py", line 5, in <module>
    from RubiksCubeUtils.CustomDecorators import with_move_attribute
  File "/builds/johndoe/foo/RubiksCubeUtils/CustomDecorators.py", line 3, in <module>
    from ursina import invoke
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/ursina/__init__.py", line 10, in <module>
    from ursina.window import instance as window
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/ursina/window.py", line 367, in <module>
    instance = Window()
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/ursina/window.py", line 59, in __init__
    self.screen_resolution = [get_monitors()[0].width, get_monitors()[0].height]
  File "/builds/johndoe/foo/venv/lib/python3/site-packages/screeninfo/screeninfo.py", line 32, in get_monitors
    raise ScreenInfoError("No enumerators available")
screeninfo.common.ScreenInfoError: No enumerators available
DonkeyKong
  • 465
  • 1
  • 5
  • 16

1 Answers1

0

On linux in containers, it worked for me to install libxrandr library. For Debian based distros (ubuntu) use

apt install -y libxrandr2
jary
  • 1,161
  • 6
  • 9