3

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.

2 Answers2

3

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]

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Paul
  • 66
  • 4
  • Confirmed that this worked like a charm for the error I was running into. Thanks man, I'd all but given up on it. – Robert Clayton Aug 03 '19 at 07:39
  • 1
    The service xvfb is also required and works only on xenial. I also succeed to fix the issue using the code above and by adding dist:xenial in my travis file – DrIDK Aug 03 '19 at 23:44
  • 1
    @DrIDK Thanks for pointing that out---I'd forgotten that I had also added `dist: xenial` to my yml file. I'll edit my original question to include that info. – Robert Clayton Aug 04 '19 at 14:11
  • Same here! clean and painless solution to a potentially nasty issue... you made my day – fr_andres Mar 31 '20 at 15:45
0

Thanks Paul, I tried the above and had to combine resources from a few solutions to get this to work. Hopefully this can help others!

I have this working with Python 3.8 on travis ci, but needed many more xcb packages that mentioned above.

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

With this configuration, pytest is running fine with pytest-qt. I had to go through one by one the dependency failures with QT until it worked.