3

致力于了解如何对基于 PySide2 的应用程序进行自动化单元测试。但是,每当我尝试QApplication在测试中初始化实例时,无论是通过PySide2自身还是通过pytest-qtqtbot 夹具,travis-ci 都会中止测试。但是,它在本地工作。

我尝试使用qtbot和中的qapp固定装置pytest-qt,尝试不同的travis-ci发行版,例如xenialand trusty,以及包括pytest-xvfb我看到的类似 stackoverflow 问题的答案所推荐的插件,但在上述任何组合中都没有任何效果。

# .travis.yml
language: python
python:
  - "3.6"
cache: pip
dist: xenial
install: pip install -r requirements.txt
# running from top folder level to keep package on the path
script: python -m pytest tests/
# tests/test_central.py
from lysiaa.central import MyWindow

def test_giveBack(qapp):
    window = MyWindow()
    assert window.giveBack(1) == 1
# lysiaa/central.py
class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()

    def giveBack(self, param):
        return param

但是,当travis-ci尝试运行它时,它会因核心转储而中止。有人可以帮我解决这个问题吗?

============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.5.0, py-1.8.0, pluggy-0.11.0
PySide2 5.12.3 -- Qt runtime 5.12.3 -- Qt compiled 5.12.3
rootdir: /home/travis/build/robert-clayton/LYSIAA
plugins: xvfb-1.2.0, qt-3.2.2
collected 1 item                                                               
tests/test_central.py /home/travis/.travis/functions: line 104:  4092 Aborted                 (core dumped) python -m pytest tests/
The command "python -m pytest tests/" exited with 134.
4

2 回答 2

3

我只是想出一个类似的项目。我认为这是相关的: Running pytest-qt on CircleCI

我试图QT_DEBUG_PLUGINS=1在 Travis-CI 中设置为环境变量,但没有从中获得任何信息。但是,我成功添加了

addons:
  apt:
    packages:
    - x11-utils
    - libxkbcommon-x11-0
services: xvfb
dist: xenial

.travis.yml. 请注意,出于某种原因,您必须确保before-install..travis.yml

这是一个工作 travis.yml:https ://github.com/AFM-analysis/PyJibe/blob/c4406fd712d778e2f644d6d03fce0db5688801bb/.travis.yml

Travis-CI 之前:https ://travis-ci.org/AFM-analysis/PyJibe/jobs/564834411

Trivis-CI 之后:https ://travis-ci.org/AFM-analysis/PyJibe/jobs/565690825

[编辑:我已经添加services: xvfbdist: xenial根据 DrIDK 的评论]

于 2019-07-30T21:54:50.633 回答
0

谢谢保罗,我尝试了上述方法,并且必须结合一些解决方案的资源才能使其正常工作。希望这可以帮助其他人!

我在 travis ci 上使用 Python 3.8,但需要上面提到的更多 xcb 包。

addons:
  apt:
    packages:
    - x11-utils
    - libxkbcommon-x11-0
    - libxcb-randr0-dev
    - libxcb-xtest0-dev
    - libxcb-xinerama0-dev
    - libxcb-shape0-dev
    - libxcb-xkb-dev
    - libxcb-render-util0
    - libxcb-icccm4
    - libxcb-keysyms1
    - libxcb-image0
services: xvfb

使用此配置,pytest 与 pytest-qt 运行良好。我不得不一一经历 QT 的依赖失败,直到它起作用。

于 2020-09-25T16:27:05.967 回答