Issue
I'm attempting to write tests for a PySide6 application using pytest. I also use tox to run these tests; however, I am running into an issue. During testing, every test fails with the output:
tests/test_application.py::test_application_startup 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, minimalegl, wayland-egl, wayland, vkkhrdisplay, offscreen, linuxfb, vnc, minimal, xcb.
Fatal Python error: Aborted
<Stacktrace omitted due to SO believing it to be spam, sorry :(>
Extension modules: xxsubtype, shiboken6.Shiboken, PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets, PySide6.QtTest, PySide6.QtUiTools, markupsafe._speedups (total: 8)
Aborted (core dumped)
Here is my tox config:
[tox]
minversion = 3.24
envlist =
py310
isolated_build = True
[testenv]
description = Invoke pytest to run automated tests
setenv =
TOXINIDIR = {toxinidir}
passenv =
HOME
SETUPTOOLS_*
PYTHONPATH
deps =
PySide6==6.4.1
qt-material==2.12
setuptools
coverage
pytest
pytest-qt
commands =
coverage run --context={envname} -m pytest --strict-markers --strict-config --tb=short --verbose --capture=no --full-trace
parallel_show_output = True
My environment:
Ubuntu 20.04
Python 3.10.8
tox==3.27.1
Failing test code:
from PySide6.QtWidgets import QApplication
def test_application_startup() -> None:
"""Ensure the application builds and configures."""
# Run the application
QApplication(sys.argv)
Note that I also have tox-conda
install in my environment, however, I am able to get this issue to show without it.
Since I am running Miniconda, I looked into installing PySide6 using it instead of pip to no success. Running the command in my tox config in my terminal results in a success, so I believe I have my system ready. This just fails with tox, and only tox.
Solution
tox offers isolation, this also means that environment variables are not passed in automatically.
I have no experience with PyQT6, so I do not know specific environment variables, but you could try to allow all variables as a starter.
passenv = *
If this works, you could then read more about PyQT6 and figure out which environment variables are necessary.
Answered By - Jürgen Gmach
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.