I am trying to run a bazel test
defined using sh_test
that calls a binary that uses gnuplot
as its backend (through matplotplusplus
)
If I call the binary directly, it will work without any issues and the plots are shown, but when I use bazel test
, I get this error:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
It seems Bazel is blocking access to some path or environment variable.
How can I fix this error and allow the plots to be shown, or at least the tests proceed in a headless way?
Things I have tried:
--strategy
and --spawn_strategy
to local
--test_strategy
to standalone
local=True
to sh_test
Direct binary may run because it runs in current shell session which could have access and connect to display.
During Bazel test X Windows may or may not be available for the same. Tests that need an X server should start Xvfb.
Try to install Xvfb and pass the test argument --enable_display=True
to Bazel
Please refer the bazel doc here.