QApplication instance/qtbot fixture causes travis-ci to abort and core dump

你离开我真会死。 提交于 2020-04-13 16:51:28

问题


Working on understanding how to go about automated unit testing for PySide2-based applications. However, whenever I attempt to initialize a QApplication instance within the tests, be it through PySide2 itself or through pytest-qt's qtbot fixture, travis-ci aborts the test. It works locally, however.

I've attempted using the qtbot and qapp fixtures from pytest-qt, trying different travis-ci distros like xenial and trusty, as well as including the pytest-xvfb plugin as I've seen recommended by a similar stackoverflow question's answer, but nothing worked in any combination of the above.

# .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

When travis-ci tries running this, however, it aborts with a core dump. Could anyone please help me with this issue?

============================= 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.

回答1:


I just figured this out for a similar project. I think this is related: Running pytest-qt on CircleCI

I tried to set QT_DEBUG_PLUGINS=1 as an environment variable in Travis-CI, but did not get any information out of that. However, I succeeded by adding

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

to .travis.yml. Note that for some reason you have to make sure that there is no before-install section in .travis.yml.

Here is a working travis.yml: https://github.com/AFM-analysis/PyJibe/blob/c4406fd712d778e2f644d6d03fce0db5688801bb/.travis.yml

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

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

[EDIT: I have added services: xvfb and dist: xenial as per DrIDK's comment]



来源:https://stackoverflow.com/questions/56281631/qapplication-instance-qtbot-fixture-causes-travis-ci-to-abort-and-core-dump

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!