【发布时间】:2018-05-27 21:28:40
【问题描述】:
我是PyQt 的新手,但我将使用pytest 和pytest-qt 插件来测试我的PyQt5 应用程序。我有一些使用SWTBot 和RCPTT 的Java GUI 测试经验,在那里我可以实时看到在测试期间控件和整个GUI 会发生什么。我想用我的新 python 工具有这样的行为,但似乎pytest-qt 以某种背景方式测试 GUI。所有代码都按我的预期工作,但在测试期间我看不到 GUI。代码很简单,就像教程中一样:
from tests.test import MyApp
from time import sleep
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
def test_myapp(qtbot):
app = QApplication([])
window = MyApp()
# window.show()
# app.exec_()
qtbot.addWidget(window)
qtbot.mouseClick(window.buttonBox.buttons()[0], Qt.LeftButton)
sleep(5)
assert window.label.text() == 'accept'
如果我取消注释 window.show() 行(他们在 tutorial 中这样做),我会看到一个奇怪的窗口,其中包含冻结的背景:
我想理论上可以显示界面,因为我知道 PyQt5 在 python shell (more) 中工作:
例如,您可以从 Python shell 提示符创建小部件,与它们交互,并且仍然能够输入其他 Python 命令
但是不知道怎么用pytest-qt来实现
【问题讨论】:
标签: python user-interface pyqt5 pytest