4

I've got some unit tests for my (python) Qt gui, which require QApplication instance, but creating one always fail for me (i.e. ends in core dumped and application abort at line with QApplication()). What I've tried so far is:

  • creation methods:
    • plain app = QApplication() on module level
    • app = QApplication(['--platform offscreen'])
    • using fixture from pytest-qt that manages QApplication object creation, i.e. passing qtbot to my tests
  • I've even tried both python ports of qt, i.e.:
    • PyQt5
    • PySide2
  • Virtual screens:

I've tried using https://github.com/nektos/act to debug this issue locally, but using this approach issue was not reproducible (i.e. everything worked as expected) until I've added herbstluftwm, i.e. only thing I was able to achieve is that locally it also started to fail.

What else I can check? Have you seen QApplication created successfully on github actions? BTW. How to get Qt's output to be visible in github actions? (I've added env: QT_DEBUG_PLUGINS: 1 and sill can't see any errors)

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
konserw
  • 494
  • 2
  • 10

1 Answers1

4

Thanks to @eyllanesc request for MRE I've created this https://github.com/konserw/mre minimal example repo which allowed me to find solution on my own. It turns out that in you need to install xvfb and libxkbcommon-x11-0, but you must NOT run xvfb service or herbstluftwm. Then you need to run your test command (coverage in my case) using xvfb-run, which in case of github actions require absolute path to coverage, like that:

xvfb-run `which coverage` run -m pytest

I hope this would help future users of github actions struggling to get PyQt5 or PySide2 GUI tests running.

BTW. pytest was silencing output from Qt's QT_DEBUG_PLUGINS, so replacing test command with plain python call with some minimal script that reproduces problem was key here. see https://github.com/konserw/mre/runs/509156615?check_suite_focus=true

konserw
  • 494
  • 2
  • 10
  • I use PyQt5 installed with pip. On top of what you said, I had to install all these packages with apt: `sudo apt install -y xvfb x11-utils libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0` – Rémi Ducceschi Mar 30 '21 at 23:11
  • The list of packages to install with `apt` is simpler. Just running this: `sudo apt-get -qq install libxcb-xinerama0 pyqt5-dev-tools`, will give all that you need. – Carlos Cordoba Oct 18 '21 at 18:42