PyQt testing with nose - a thread from the python-testing mailing list which describes various options LDTP uses accessibility libraries to perform GUI testing Due to the conflicting libraries in use on Linux desktops (ATK vs. D-Bus) and the fact that D-Bus-based accessibility is often disabled for Qt applications.
I have a parent widget that in some cases calls a custom QDialog to get user input. How do I write a unit test to ensure the dialog is called, and that it will handle correct input correctly?Here's a mini example: from PyQt5.QtWidgets import QDialog, QVBoxLayout, QWidget, QLabel, QApplicationfrom PyQt5.Qt import pyqtSignal, QPushButton, pyqtSlot, QLineEditimport sysclass PopupDialog(QDialog):result = pyqtSignal(str)def init(self):super.initlayout = QVBoxLayout(self)self.setLayout(layout)lbl = QLabel('That's not a full number!
Well there are few ways to check if the QDialog is created,1) patch the PopupDialog and verify if it was called. From unittest.mock import patch@patch('temp2.PopupDialog')def testPopupDialog(self, mockdialog):self.w.counterfld.setText(str('A'))self.w.btn.clickmockdialog.assertcalledonce2) To interact with the PopupDialog you may have to do a bit more.
Def testPopupDialogInteraction(self):self.w.counterfld.setText(str('A'))self.w.btn.clickif hasattr(self.w.dialog, 'field'):self.w.dialog.field.setText(str(1))self.w.dialog.btn.clickvalue = self.w.field.textself.assertEqual(value, str(1. 100))raise Exception('dialog not created')On a different note, there is a better way to verify the user input i.e QRegExpValidator. Check thisIn the present method, it will continue creating a Popup everytime a user inputs improper value and would create a poor user-experience(UX). Even websites use validators instead of Popups.