[PyQt] QTreeView + sort + delete = crash
John F Sturtz
john at sturtz.org
Sat May 4 18:13:22 BST 2019
Hi Florian. Thanks for the response. I was unaware of the model tester. Sounds very interesting. Unfortunately, my attempts to use it so far have been unrewarding.
First, I tried installing pytest-qt using pip. Following that, I am able to successfully import pytestqt. But if I try to import pytestqt.modeltest, I get this message:
>>> import pytestqt.modeltest
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import pytestqt.modeltest
File "C:\Users\jfs\AppData\Local\Programs\Python\Python37\lib\site-packages\pytestqt\modeltest.py", line 55, in <module>
HAS_QT_TESTER = hasattr(qt_api.QtTest, "QAbstractItemModelTester")
AttributeError: '_QtApi' object has no attribute 'QtTest'
which I don't quite understand. :-/
Undaunted, I tried updating PyQt5 to 5.12.1 and using QAbstractItemModelTester. I put the following line in the test app:
tester = QtTest.QAbstractItemModelTester(dlg.model, QtTest.QAbstractItemModelTester.FailureReportingMode.Warning)
That didn't generate any output. The documentation says "In a test case [https://doc.qt.io/qt-5/qtest-overview.html] it is sufficient to create an instance, passing the model that needs to be tested to the constructor". So I guess it must be the case that I haven't properly created a test case. Still working on it ...
/John
On 5/3/2019 1:36:04 AM, Florian Bruhin <me at the-compiler.org> wrote:
On Thu, May 02, 2019 at 10:25:38PM -0500, John F Sturtz wrote:
> Any help or insight would surely be appreciated.
You might want to try running pytest-qt's item model tester over your model:
https://pytest-qt.readthedocs.io/en/latest/modeltester.html
(I suppose with PyQt > 5.11 you can also use QtTest.QAbstractItemModelTester
outside of pytest, but I never tried)
It catches a lot of little issues with model implementations and (hopefully)
tells you what's wrong.
Florian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190504/afde2bd1/attachment.html>
More information about the PyQt
mailing list