1

我使用 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

4

1 回答 1

0

毫不奇怪,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文件夹。

于 2020-11-24T22:33:02.180 回答