I am trying to run some tests using pytest in Gitlab CI/CD. Some of those tests include rendering using the Pyglet module.
I get an error:
pyglet.window.NoSuchConfigException: No standard config is available.
I have tried both headless=True and False.
Then I found xvfb so I tried to run the test by making a virtual screen:
before_script:
- apt-get install -y xorg-dev libglu1-mesa libgl1-mesa-dev xvfb libxinerama1 libxcursor1
- export DISPLAY=:0
script:
- conda run -n myenv-3.10-cpu xvfb-run -a -s "-screen 0 1400x900x24 +extension RANDR" python -m pytest -vvv ./tests
This did not solve my issue since I got the same error. Note that the tests run perfectly fine locally on my laptop.
Traceback:
from pyglet.window import key
/root/miniconda3/envs/myenv-3.10-cpu/lib/python3.10/site-packages/pyglet/window/__init__.py:1929: in <module>
gl._create_shadow_window()
/root/miniconda3/envs/myenv-3.10-cpu/lib/python3.10/site-packages/pyglet/gl/__init__.py:165: in _create_shadow_window
_shadow_window = ShadowWindow()
/root/miniconda3/envs/myenv-3.10-cpu/lib/python3.10/site-packages/pyglet/gl/__init__.py:159: in __init__
super().__init__(width=1, height=1, visible=False)
This is an example test that will fail with the prementioned error:
def test_pyglet():
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=window.width // 2, y=window.height // 2,
anchor_x='center', anchor_y='center')
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
ckeck this code snippet.