繁体   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