标签: pytest-qt

如何使用pytest-qt点击QMessageBox?

PyQt我正在为应用程序创建一些单元测试pytest-qt。我想创建打开的图形窗口,进行一些测试然后关闭窗口,而不是为每个测试打开一个新窗口,即。对窗口本身使用模块固定装置。我成功地完成了这部分,通过调用本地函数 aQtBot而不是使用默认的固定装置,并删除模拟装置。所以我已经非常接近我的目标了。

但是,但我无法关闭窗口(并测试QMessageBox关闭事件)。

我红色示例,例如 如何处理模式对话框及其git讨论,或qmessage问题;这似乎与我的问题很接近。建议使用计时器等待出现,QMessageBox然后单击按钮选项,但显然我无法正确应用它们。在我的尝试中,pytest获得了平仓需求,但没有点击该dialog框。所以,我必须点击自己来完成测试。

这是一个带有 file 的小示例GUI.py

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys

from PyQt5 import QtGui, QtCore, QtWidgets

from PyQt5.QtWidgets import *
from PyQt5.QtCore import QCoreApplication, Qt, QObject
from PyQt5.QtGui import QIcon


class Example(QMainWindow):
    def __init__(self, parent = None):
        super().__init__()
        self.initUI(self)

    def initUI(self, MainWindow):
        # centralwidget
        MainWindow.resize(346, 193)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        # The Action to quit …
Run Code Online (Sandbox Code Playgroud)

python pyqt pytest pyqt5 pytest-qt

6
推荐指数
1
解决办法
2900
查看次数

在 CircleCI 上运行 pytest-qt

我正在尝试pytest-qt在 CircleCI 上运行需要(用于测试 PySide2 对话框)的测试。我收到以下错误:

xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.0.0, py-1.8.0, pluggy-0.12.0 -- /home/circleci/project-caveman/venv/bin/python3
cachedir: .pytest_cache
PySide2 5.13.0 -- Qt runtime 5.13.0 -- Qt compiled 5.13.0
rootdir: /home/circleci/project-caveman
plugins: cov-2.7.1, xvfb-1.2.0, qt-3.2.2
collected 1 item                                                               

tests/test_main.py::test_label_change_on_button_press Fatal Python error: Aborted

Aborted (core dumped)
Exited with code 134
Run Code Online (Sandbox Code Playgroud)

我正在使用这个配置文件:

version: 2
jobs:
  build:
    working_directory: ~/project-caveman
    docker:
      - image: circleci/python:3.6.8-stretch
    steps: …
Run Code Online (Sandbox Code Playgroud)

python pytest circleci pytest-qt

3
推荐指数
1
解决办法
874
查看次数

如何使用 pytest-qt 自动拖动鼠标?

我有一个 pyqt 窗口,可以在按下鼠标时跟踪鼠标移动。我正在尝试编写一个测试来使用 pytest-qt 自动执行此移动。

这是一个示例类:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QApplication

class Tracker(QDialog):
    def __init__(self, parent=None):
        super(Tracker, self).__init__(parent)
        self.location = None
        self.cur = QCursor()
        layout = QVBoxLayout()
        self.label = QLabel()
        layout.addWidget(self.label)
        self.setLayout(layout)
        self.setModal(True)
        self.showFullScreen()

    def mouseReleaseEvent(self, e):
        x = self.cur.pos().x()
        y = self.cur.pos().y()
        self.location = (x, y)
        return super().mouseReleaseEvent(e)

    def mouseMoveEvent(self, e):
        x = self.cur.pos().x()
        y = self.cur.pos().y()
        self.label.setText(f'x: {x}, y: {y}')
        return super().mouseMoveEvent(e)

if __name__ == '__main__':

    import sys

    app = QApplication(sys.argv) …
Run Code Online (Sandbox Code Playgroud)

python pyqt pyqt5 pyautogui pytest-qt

3
推荐指数
1
解决办法
1189
查看次数

标签 统计

pytest-qt ×3

python ×3

pyqt ×2

pyqt5 ×2

pytest ×2

circleci ×1

pyautogui ×1