pytest Segmentation fault with PySide6 (6.7.0)
-
Hi all,
I'm still checking but problem appeared last week and I think it is caused by PySide upgrade to version 6.7.0. The problem is - pytest doesn't work anymore. I.e. if I have a test without Qt - everything is fine. If I unclude anything from Qt into the test - it raises a Segmentation Fault.So, here is a very simple test case:
from PySide6.QtSql import QSqlDatabase def test_db(): db = QSqlDatabase.addDatabase("QSQLITE", "TEST")
I run pytest and then see this:
pytest test_db.py ==================================================================== test session starts ==================================================================== platform linux -- Python 3.11.8, pytest-8.1.1, pluggy-1.4.0 PySide6 6.7.0 -- Qt runtime 6.7.0 -- Qt compiled 6.7.0 rootdir: /home/projects/tests configfile: pytest.ini plugins: anyio-4.3.0, time-machine-2.14.1, requests-mock-1.11.0, qt-4.4.0, hypothesis-6.100.1, typeguard-4.2.1 collected 1 item test_db.py::test_db Fatal Python error: Segmentation fault Current thread 0x00007867f5837740 (most recent call first): File "/usr/lib/python3.11/site-packages/_pytest/python.py", line 195 in pytest_pyfunc_call File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102 in _multicall File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119 in _hookexec File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501 in __call__ File "/usr/lib/python3.11/site-packages/_pytest/python.py", line 1772 in runtest File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 172 in pytest_runtest_call File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102 in _multicall File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119 in _hookexec File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501 in __call__ File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 240 in <lambda> File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 340 in from_call File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 239 in call_and_report File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 134 in runtestprotocol File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 115 in pytest_runtest_protocol File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102 in _multicall File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119 in _hookexec File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501 in __call__ File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 364 in pytest_runtestloop File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102 in _multicall File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119 in _hookexec File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501 in __call__ File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 339 in _main File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 285 in wrap_session File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 332 in pytest_cmdline_main File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102 in _multicall File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119 in _hookexec File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501 in __call__ File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 174 in main File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 197 in console_main File "/usr/bin/pytest", line 8 in <module> Extension modules: _time_machine, _cffi_backend, shiboken6.Shiboken, PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets, PySide6.QtTest, PySide6.QtSql (total: 8) Segmentation fault (core dumped)
I'm trying to understand how to debug it and should I address it to
pytest
or toPySide
... Any ideas? -
First thing; for the SQL classes you need to make sure a QCoreApplication instance exists. But 6.7.0 has a few issues with star imports, this will be fixed in 6.7.1 (see https://bugreports.qt.io/browse/PYSIDE-2674 ).
-
@friedemannkleint ,
Ok, this is indeed good point that I always forget.
I changed it tofrom PySide6.QtWidgets import QApplication from PySide6.QtSql import QSqlDatabase def test_db(): app = QApplication([]) db = QSqlDatabase.addDatabase("QSQLITE", "TEST")
and it doesn't raise Segmentation fault anymore. So I'll look into my test cases to see how to change them...
But do you know why below code fails with Segmentation fault either?
from PySide6.QtWidgets import QWidget def test_db(): widget = QWidget()
-
Same reason, widgets require a QApplication instance ;-)
-
@friedemannkleint
Thanks a lot for your time. It appears to be a gap in my knowledge :) -