The Python unit testing framework, sometimes referred to as “PyUnit,” is a Python language version of JUnit, by Kent Beck and Erich Gamma. JUnit is, in turn, a Java version of Kent’s Smalltalk testing framework. Each is the de facto standard unit testing framework for its respective language. 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 am trying to build an app using PyQt5 that has a secondary window 'popup' when an item in a QListWidget
is double clicked.
Here is the code:
I want a second window to popup when one of the names in the listbox is double clicked, but I can't for the life of me get the examplePopup
widget to draw on screen. Thanks in advance for the help.
2 Answers
The popup window doesn't show because you are not keeping a reference to it, and so it gets garbage-collected as soon as buildExamplePopup
returns.
You can easily fix the problem like this:
ekhumoroekhumoroI can't really tell why it's not working with QWidget
since it does work if the second widget is initialized inside the __main__
. However you can make use of a QDialog
to achieve the same result:
I also changed a bit your code adding the @pyqtSlot
decorator to the itemDoubleClicked
signal slot handler (you should not declare slots as static).
Not the answer you're looking for? Browse other questions tagged pyqt5python-3.5 or ask your own question.
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:
So in this case, I'd want to write a unit test that inserts different values into self.field and then tests that it works without PopupDialog for integers but that the PopupDialog is called when inserting a string.
(I know I could just test the functionality without the dialog, and that for this problem, the QDialog is not actually needed. I just tried to keep the example simple. Baseline is: I can get the unit test through the steps until the popup dialog is created, but how can I then test that it is indeed created, and then interact with it to test the result?)
(I'm using PyQt5 in Python3.6 on Windows.)
![Python Unit Test Qt That Popup Is Created Python Unit Test Qt That Popup Is Created](https://docs.microsoft.com/en-us/visualstudio/python/media/unit-test-debugging.png?view=vs-2019)
1 Answer
Well there are few ways to check if the QDialog
is created,
1) patch the PopupDialog
and verify if it was called.
2) To interact with the PopupDialog
you may have to do a bit more.
On a different note, there is a better way to verify the user input i.e QRegExpValidator
. Check this SO answer
In 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.