簡體   English   中英

為什么在使用 pytest-qt 進行測試時出現致命的 Python 錯誤?

[英]Why a Fatal Python error when testing using pytest-qt?

我使用 pytest-qt 的第一次測試立即失敗,出現致命的 Python 錯誤。 我將代碼簡化為這個(一個永遠不會通過的測試,但不應該崩潰):

from PyQt5 import QtCore as qtc


class sut(qtc.QObject):
    sig_sig_sputnik = qtc.pyqtSignal()

    def __init__(self):
        super().__init__()

    def listen(self):
        pass


def test_emit(qtbot):
    uut = sut()
    with qtbot.waitSignal(sut.sig_sig_sputnik, raising=True):
        uut.listen()

執行此操作失敗:

=== test session starts ====
platform linux -- Python 3.6.9, pytest-5.4.3, py-1.8.1, pluggy-0.13.1
PyQt5 5.10.1 -- Qt runtime 5.12.9 -- Qt compiled 5.9.5
rootdir: [~]/src/npsw/frameworks/rtx, inifile: pytest.ini
plugins: qt-3.3.0, metadata-1.10.0, html-2.1.1, jnj-radish-1.4.0
collected 1 item                                                                                                                                                             

test_min.py Fatal Python error: Aborted

Current thread 0x00007f7c8411c740 (most recent call first):
  File "[~]/.local/lib/python3.6/site-packages/pytestqt/plugin.py", line 57 in qapp
  File "[~]/.local/lib/python3.6/site-packages/_pytest/fixtures.py", line 792 in call_fixture_func
  File "[~]/.local/lib/python3.6/site-packages/_pytest/fixtures.py", line 964 in pytest_fixture_setup
[boilerplate pytest stack from here on down]

請注意,故障發生在qapp夾具中,但測試使用的是qtbot (它使用qapp本身)。

我認識到 PyQt5、Qt 運行時和編譯的 Qt(在輸出的第二行)顯示的版本之間存在不匹配。 我的 18.04 Ubuntu 系統將 Qt5.9 作為系統范圍的 Qt(來自標准仿生 PPA),但開發組使用的是 5.12。 5.12 運行時安裝到特定位置,對於此運行, LD_LIBRARY_PATH指向該位置。 如果我不使用此設置,則在 pytest 甚至開始運行之前會出現不同的錯誤:

INTERNALERROR> ImportError: /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5: symbol _ZNK15QDateTimeParser5parseER7QStringRiRK9QDateTimeb version Qt_5_PRIVATE_API not defined in file libQt5Core.so.5 with link time reference

不出所料,只是將 Qt5.12 庫復制到文件夾中存在配置問題。 我能夠制定如下解決方法:

sudo mkdir /usr/bin/platforms
sudo ln -s /our/local/libqxcb.so /usr/bin/platforms/libqxcb.so

這足以讓我在沒有崩潰的情況下運行我的測試。

正如 pytest-qt 站點的 Florian 告訴我的那樣,這個 Python:

from PyQt5.QtWidgets import QApplication
app = QApplication([])

也失敗了,但沒有太多信息。 然后我得到了一個提示

export QT_DEBUG_PLUGINS=1

額外的診斷信息將我指向該platforms文件夾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM