运行 CircleCI 上的 pytest-qt

Running pytest-qt on CircleCI

我正在尝试 运行 在 CircleCI 上需要 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 运行time 启用调试模式,以便打印一些错误信息。这可以通过设置环境变量 QT_DEBUG_PLUGINS:

来完成
$ QT_DEBUG_PLUGINS=1 pytest -sv

现在可以立即清楚运行 测试容器中缺少的内容。上述命令的输出片段:

从插件元数据中获取密钥 ("xcb")
QFactoryLoader::QFactoryLoader() 检查目录路径“/usr/local/bin/platforms” ...
<b>无法加载库 /home/circleci/.local/lib/python3.6/site-packages/PySide2/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: 无法打开共享对象文件: 没有这样的文件或目录)</b>
QLibraryPrivate::loadPlugin 在“/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: 无法在“”中加载 Qt 平台插件 "xcb",即使已找到。
此应用程序无法启动,因为无法初始化 Qt 平台插件。重新安装应用程序可能会解决此问题。

可用的平台插件有:eglfs、linuxfb、minimal、miniplegl、offscreen、vnc、wayland-egl、wayland、wayland-xcomposite-egl、wayland-xcomposite-glx、webgl、xcb。

中止(核心转储)

解决这个问题很简单 - 安装 libxkbcommon-x11-0 软件包:

$ sudo apt update && sudo apt install -y libxkbcommon-x11-0

在 CircleCI 配置中添加这一行(在测试作业之前的某处,例如在安装包依赖项的作业中)并且测试应该 运行 没问题。

除此之外,全局设置 QT_DEBUG_PLUGINS=1 是有意义的,这样您可以在将来对最终的 Qt 运行time 故障做出反应。

xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!

如果您想消除该警告,请安装 x11-utils:

$ sudo apt install x11-utils

仅限Centos 6.5 run:yum安装xdpyinfo,成功解决