Fatal Python Error When Running Pytest With Qt
Solution 1:
I had this issue today as well. The solution for me was to create a pytest.ini file in my tests directory and include this in it.
[pytest]qt_api=pyqt5
From https://github.com/pytest-dev/pytest-qt
To force a particular API, set the configuration variable qt_api in your pytest.ini file to pyqt5 or pyside2
Once I set the qt_api in the pytest.ini the tests ran without any issues
Solution 2:
I recognize this output, i had the same problem myself just recently
The problem was that i had forgotten to create the QApplication
before creating the widget/window i wanted to test
So one way to solve the problem is this:
def test_something():
test_app = QtWidgets.QApplication(sys.argv) # <-----
main_win = some_application.main_window.MainWindow()
[...]
Alternatively you can use a pytest fixture which takes care of setup/teardown
pytest-qt includes the qtbot fixture. From the project readme file:
The main usage is to use the
qtbot
fixture, responsible for handlingqApp
creation as needed [...]
So in that case this is enough:
deftest_something(qtbot): # <-----
main_win = some_application.main_window.MainWindow()
[...]
Solution 3:
In my case I ran into the Fatal Python error: aborted
message, but it turned out to be due to my environment.
I was seeing failures running the test suite in GitHub Codespaces but when I went the extra step of cloning it, the suite worked under Crostini on my Chromebook. Once I realized that it worked where I had a DISPLAY
variable defined I realized that the Qt tests probably required a DISPLAY
, whether xvfb
or a "real" display, so I installed xvfb
and then used xvfb-run pytest -v
and was able to see the test suite succeed.
Post a Comment for "Fatal Python Error When Running Pytest With Qt"