在CircleCI上运行pytest-qt

3

我正在尝试在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

任何帮助都非常感激,提前致谢。

你能试着读取错误时的跟踪信息吗?在test_label_change_on_button_press函数中,添加以下代码:import faulthandlerfaulthandler.enable(),也许可以帮助找到错误。可能是因为xfvb-run无法找到显示器,但没有错误信息很难确定。 - hoefling
@hoefling 请查看 https://circleci.com/gh/redduntur/project-caveman/46。 - user6152171
2个回答

5

我已经在本地拉取了容器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

0
在Centos6.5中只需要运行命令:yum install xdpyinfo,就可以成功解决它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接