2

To test my code that is a plugin for a pyqt5 application, I'm writing tests that create dummy QApplication objects.

However, whenever I try to create a QApplication code locally works as expected but segfaults in travis.

I pinpointed the issue to the following line:

qapp = QtWidgets.QApplication([])

This is the error I'm getting (taken from the travis log):

tests/idaplugin/test_plugin.py::test_plugin_creation /home/travis/.travis/job_stages: line 53:  2382 Aborted                 (core dumped) PYTHONPATH=. py.test ./${PROJECT} ./tests/${PROJECT} --verbose --cov-report= --cov=$PROJECT

Here is the travis-ci job: https://travis-ci.org/nirizr/rematch/jobs/219490893

And here's the snippet of the test:

def test_plugin_creation():
    from PyQt5 import QtWidgets
    qapp = QtWidgets.QApplication([])

    # test be here, requires a QApp to function 
    plugin = plugin_rematch.PLUGIN_ENTRY()

    ... extra test code removed ...

Is this an issue with travis or am I doing something wrong?

NirIzr
  • 3,131
  • 2
  • 30
  • 49

2 Answers2

3

You'll need to run xvfb on Travis to be able to execute graphical applications (if you don't need any GUI, use QCoreApplication instead).

You can either follow Travis' docs, or (since it looks like you're using pytest), use my pytest-xvfb plugin.

By the way: pytest's -s flag (to not hide output from "passing" tests) is quite useful when debugging issues like this.

The Compiler
  • 11,126
  • 4
  • 40
  • 54
1

On gitlab CI/CD you can use QT_QPA_PLATFORM: "offscreen"

See https://stackoverflow.com/a/55442821/6000005

azzamsa
  • 1,805
  • 2
  • 20
  • 28