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

Core dumped when running pytest-qt tests #468

Closed Kastakin closed 1 year ago

Kastakin commented 1 year ago

I am trying to integrate pytest-qt tests to my existing application. I have just started going through the tutorial on the docs and I have written a barebone test:

from src.main.python.pyes.main import MainWindow
from pytestqt.qtbot import QtBot

class TestMainWindow:

    def test_init(qtbot: QtBot):
        window = MainWindow()
        window.show()
        qtbot.addWidget(window)

The folder structure from which I import the MainWindow widget might look strange but its related to the packaging method I use, pyes is the main module.

Running the test result in the following error:

Test session starts (platform: linux, Python 3.10.8, pytest 7.2.0, pytest-sugar 0.9.6)
cachedir: .pytest_cache
PySide6 6.4.0.1 -- Qt runtime 6.4.0 -- Qt compiled 6.4.0
rootdir: /home/lorenzo/Coding/PyES, configfile: pyproject.toml
plugins: cov-4.0.0, xvfb-2.0.0, qt-4.2.0, sugar-0.9.6
collecting ... Fatal Python error: Aborted

Current thread 0x00007f04ad601b80 (most recent call first):
  File "/home/lorenzo/Coding/PyES/src/main/python/pyes/windows/window.py", line 33 in __init__
  File "/home/lorenzo/Coding/PyES/tests/test_windows.py", line 8 in test_init
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/python.py", line 195 in pytest_pyfunc_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/python.py", line 1789 in runtest
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 167 in pytest_runtest_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 260 in <lambda>
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 339 in from_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 259 in call_runtest_hook
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 220 in call_and_report
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 131 in runtestprotocol
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 112 in pytest_runtest_protocol
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 349 in pytest_runtestloop
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 324 in _main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 270 in wrap_session
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 317 in pytest_cmdline_main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 167 in main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 190 in console_main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/bin/pytest", line 8 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, xxsubtype, shiboken6.Shiboken, PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets, PySide6.QtTest, PySide6.QtNetwork, pandas._libs.tslibs.np_datetime, pandas._libs.tslibs.dtypes, pandas._libs.tslibs.base, pandas._libs.tslibs.nattype, pandas._libs.tslibs.timezones, pandas._libs.tslibs.tzconversion, pandas._libs.tslibs.ccalendar, pandas._libs.tslibs.fields, pandas._libs.tslibs.timedeltas, pandas._libs.tslibs.timestamps, pandas._libs.properties, pandas._libs.tslibs.offsets, pandas._libs.tslibs.parsing, pandas._libs.tslibs.conversion, pandas._libs.tslibs.period, pandas._libs.tslibs.vectorized, pandas._libs.ops_dispatch, pandas._libs.missing, pandas._libs.hashtable, pandas._libs.algos, pandas._libs.interval, pandas._libs.tslib, pandas._libs.lib, pandas._libs.hashing, pandas._libs.ops, pandas._libs.arrays, pandas._libs.index, pandas._libs.join, pandas._libs.sparse, pandas._libs.reduction, pandas._libs.indexing, pandas._libs.internals, pandas._libs.writers, pandas._libs.window.aggregations, pandas._libs.window.indexers, pandas._libs.reshape, pandas._libs.tslibs.strptime, pandas._libs.groupby, pandas._libs.testing, pandas._libs.parsers, pandas._libs.json, PIL._imaging, PySide6.QtSvg, PySide6.QtOpenGLWidgets (total: 64)
[1]    95620 IOT instruction (core dumped)  pytest tests/test_windows.py -v

Other tests that does not require pytest-qt extension work as intended, I don't understand what is causing this issue in particular. These are the ini_options in my pyproject.toml:

[tool.pytest.ini_options]
testpaths = "tests"
pythonpath = "src/main/python/pyes"
addopts = "--cov=src/main/python/pyes --cov-report=html"
qt_api = "pyside6"

I am open to give any more information that might help in solving the issue.

The-Compiler commented 1 year ago

What output do you get when running pytest with the -s option?

Kastakin commented 1 year ago

What output do you get when running pytest with the -s option?

The output is quite similar, there is a warning regarding the need of a QApplication object before a QWidget:

pytest tests/test_windows.py -s
Test session starts (platform: linux, Python 3.10.8, pytest 7.2.0, pytest-sugar 0.9.6)
PySide6 6.4.0.1 -- Qt runtime 6.4.0 -- Qt compiled 6.4.0
rootdir: /home/lorenzo/Coding/PyES, configfile: pyproject.toml
plugins: cov-4.0.0, xvfb-2.0.0, qt-4.2.0, sugar-0.9.6
collecting ... QWidget: Must construct a QApplication before a QWidget
Fatal Python error: Aborted

Current thread 0x00007f0f6324eb80 (most recent call first):
  File "/home/lorenzo/Coding/PyES/src/main/python/pyes/windows/window.py", line 33 in __init__
  File "/home/lorenzo/Coding/PyES/tests/test_windows.py", line 6 in test_init
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/python.py", line 195 in pytest_pyfunc_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/python.py", line 1789 in runtest
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 167 in pytest_runtest_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 260 in <lambda>
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 339 in from_call
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 259 in call_runtest_hook
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 220 in call_and_report
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 131 in runtestprotocol
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/runner.py", line 112 in pytest_runtest_protocol
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 349 in pytest_runtestloop
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 324 in _main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 270 in wrap_session
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 317 in pytest_cmdline_main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 167 in main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 190 in console_main
  File "/home/lorenzo/.cache/pypoetry/virtualenvs/pyes-YsROe161-py3.10/bin/pytest", line 8 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, xxsubtype, shiboken6.Shiboken, PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets, PySide6.QtTest, PySide6.QtNetwork, pandas._libs.tslibs.np_datetime, pandas._libs.tslibs.dtypes, pandas._libs.tslibs.base, pandas._libs.tslibs.nattype, pandas._libs.tslibs.timezones, pandas._libs.tslibs.tzconversion, pandas._libs.tslibs.ccalendar, pandas._libs.tslibs.fields, pandas._libs.tslibs.timedeltas, pandas._libs.tslibs.timestamps, pandas._libs.properties, pandas._libs.tslibs.offsets, pandas._libs.tslibs.parsing, pandas._libs.tslibs.conversion, pandas._libs.tslibs.period, pandas._libs.tslibs.vectorized, pandas._libs.ops_dispatch, pandas._libs.missing, pandas._libs.hashtable, pandas._libs.algos, pandas._libs.interval, pandas._libs.tslib, pandas._libs.lib, pandas._libs.hashing, pandas._libs.ops, pandas._libs.arrays, pandas._libs.index, pandas._libs.join, pandas._libs.sparse, pandas._libs.reduction, pandas._libs.indexing, pandas._libs.internals, pandas._libs.writers, pandas._libs.window.aggregations, pandas._libs.window.indexers, pandas._libs.reshape, pandas._libs.tslibs.strptime, pandas._libs.groupby, pandas._libs.testing, pandas._libs.parsers, pandas._libs.json, PIL._imaging, PySide6.QtSvg, PySide6.QtOpenGLWidgets (total: 64)
[1]    101199 IOT instruction (core dumped)  pytest tests/test_windows.py -s
The-Compiler commented 1 year ago

You forgot the self argument for your test method, which means you're not actually using the qtbot fixture.

Kastakin commented 1 year ago

That is so dumb that I am ashamed of even had to ask that... Thank you very much!

The docs are very well written, maybe it might be useful to clarify further this "edge case" when working with class based tests? Thank you again and I'm terribly sorry if I wasted your time!