pytest-dev / pytest-qt

pytest plugin for Qt (PyQt5/PyQt6 and PySide2/PySide6) application testing
https://pytest-qt.readthedocs.io
MIT License
409 stars 70 forks source link

Segfault on Linux with PyQt6 #550

Closed NMertsch closed 7 months ago

NMertsch commented 7 months ago

After installing pyqt6 and pytest-qt, the following test causes a segfault on Linux, but it works fine on Windows.

Code:

def test(qtbot):
    pass

Output:

[...]
test.py Fatal Python error: Aborted
Current thread 0x00007fca866cdb80 (most recent call first):
  File "/usr/local/lib/python3.11/site-packages/pytestqt/plugin.py", line 76 in qapp
  File "/usr/local/lib/python3.11/site-packages/_pytest/fixtures.py", line 913 in call_fixture_func
[...]
Extension modules: PyQt6.QtCore, PyQt6.QtGui, PyQt6.QtWidgets, PyQt6.QtTest (total: 4)
Aborted

Without the qtbot fixture, it passes.

Repo with CI script reproducing the issue: https://gitlab.com/NMertsch/qtbot-bug-repro

WSL Linux (crash)

Gitlab CI (crash)

Windows (works)

The-Compiler commented 7 months ago

Your repro is set to private, but likely you're missing dependencies for Qt to run properly. You'll find out more by adding -s to pytest to disable output capturing, and perhaps also doing export QT_DEBUG_PLUGINS=1.

See the docs for an overview of what libraries Qt generally expects to be installed.

You'd see the same issue with a python -c "from PyQt6.QtWidgets import QApplication; QApplication([])", this is unrelated to pytest or pytest-qt.

NMertsch commented 7 months ago

Thank you, the docs on Github Actions almost did the trick.

Additional things I needed to do:

I'm currently writing a PR to add this to the docs. Feel free to ignore or modify it :)