[英]Running pytest-qt on CircleCI
我正在嘗試在pytest-qt
上運行需要pytest-qt
(用於測試 PySide2 對話框)的測試。 我收到以下錯誤:
xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.0.0, py-1.8.0, pluggy-0.12.0 -- /home/circleci/project-caveman/venv/bin/python3
cachedir: .pytest_cache
PySide2 5.13.0 -- Qt runtime 5.13.0 -- Qt compiled 5.13.0
rootdir: /home/circleci/project-caveman
plugins: cov-2.7.1, xvfb-1.2.0, qt-3.2.2
collected 1 item
tests/test_main.py::test_label_change_on_button_press Fatal Python error: Aborted
Aborted (core dumped)
Exited with code 134
我正在使用這個配置文件:
version: 2
jobs:
build:
working_directory: ~/project-caveman
docker:
- image: circleci/python:3.6.8-stretch
steps:
- checkout
# Dependencies
- restore_cache:
keys:
- venv-{{ .Branch }}-{{ checksum "setup.py" }}
- venv-{{ .Branch }}-
- venv-
- run:
name: Install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -e .[test] --progress-bar off
- save_cache:
key: venv-{{ .Branch }}-{{ checksum "setup.py" }}
paths:
- "venv"
# Tests
- run:
name: Pytest
command: |
mkdir test-reports
. venv/bin/activate
xvfb-run -a pytest -s -v --doctest-modules --junitxml test-reports/junit.xml --cov=coveralls --cov-report term-missing
- store_test_results:
path: test-reports
- run:
name: Coveralls
command: coveralls
非常感謝任何幫助,提前致謝。
我在本地拉了容器circleci/python:3.6.8-stretch
,克隆了你的存儲庫並嘗試執行測試,而我可以重現錯誤。
首先要做的是為 Qt 運行時啟用調試模式,以便它打印一些有關錯誤的信息。 這可以通過設置環境變量QT_DEBUG_PLUGINS
來完成:
$ QT_DEBUG_PLUGINS=1 pytest -sv
現在可以立即清楚容器中缺少什么來運行測試。 來自上述命令輸出的片段:
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/bin/platforms" ...
Cannot load library /home/circleci/.local/lib/python3.6/site-packages/PySide2/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/circleci/.local/lib/python3.6/site-packages/PySide2/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/circleci/.local/lib/python3.6/site-packages/PySide2/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)"
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, webgl, xcb.
Aborted (core dumped)
解決這個問題很容易 - 安裝libxkbcommon-x11-0
包:
$ sudo apt update && sudo apt install -y libxkbcommon-x11-0
在 CircleCI 配置中添加這一行(在測試作業之前的某處,例如在安裝包依賴項的作業中),測試應該可以正常運行。
除此之外,全局設置QT_DEBUG_PLUGINS=1
是有意義的,這樣您就可以在將來對最終的 Qt 運行時故障做出反應。
找不到xdpyinfo,無法檢查X啟動! 請安裝xdpyinfo!
如果您想擺脫該警告,請安裝x11-utils
:
$ sudo apt install x11-utils
Centos6.5只運行:yum install xdpyinfo,成功解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.