Re: QTreeView + sort + delete = crash

"John F Sturtz" <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
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 <[email protected]> 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

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.