在CircleCI上运行pytest-qt [英] Running pytest-qt on CircleCI

查看:109
本文介绍了在CircleCI上运行pytest-qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CircleCI上运行需要pytest-qt的测试(用于测试PySide2对话框).我收到以下错误:

I am attempting to run tests which require pytest-qt (for testing PySide2 dialogs) on CircleCI. I am getting the following error:

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

我正在使用此配置文件:

And I am using this configuration file:

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,克隆了存储库并尝试执行测试,而我却可以重现该错误.

I have pulled the container circleci/python:3.6.8-stretch locally, cloned your repository and tried to execute the tests, whereas I could reproduce the error.

要做的第一件事是为Qt运行时启用调试模式,以便它打印一些有关错误的信息.这可以通过设置环境变量QT_DEBUG_PLUGINS:

First thing to do is to enable the debug mode for Qt runtime so it prints some info on errors. This can be done by settings the environment variable QT_DEBUG_PLUGINS:

$ QT_DEBUG_PLUGINS=1 pytest -sv

现在可以立即清除容器中缺少的内容以运行测试.上面命令输出的摘录:

Now it's immediately clear what's missing in the container to run the tests. A snippet from the output of the above command:

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软件包:

The fix for that is easy - install the libxkbcommon-x11-0 package:

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

在CircleCI配置中添加此行(例如,在测试作业之前的某个位置,例如在安装软件包依赖项的作业中),测试应该可以正常运行.

Add this line in the CircleCI config (somewhere before the tests job, for example in the job where you install package dependencies) and the test should run fine.

除此之外,全局设置QT_DEBUG_PLUGINS=1是有意义的,这样您以后就可以对最终的Qt运行时故障做出反应.

Aside from that, it makes sense to set QT_DEBUG_PLUGINS=1 globally so you can react on eventual Qt runtime failures in future.

找不到

xdpyinfo,无法检查X启动!请安装xdpyinfo!

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

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

If you want to get rid of that warning, install x11-utils:

$ sudo apt install x11-utils

这篇关于在CircleCI上运行pytest-qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆