pytest-dev / pytest-qt

pytest plugin for Qt (PyQt5/PyQt6 and PySide2/PySide6) application testing
https://pytest-qt.readthedocs.io
MIT License
408 stars 70 forks source link

_QtApi object has no attribute QtTest #560

Closed slyin87 closed 4 months ago

slyin87 commented 4 months ago

Hi,

I am using PySide6. I am not sure what I am doing. I want to do Model Test for my model. My code:

from pytestqt.modeltest import ModelTester

model = WorkNodeTreeModel()
qt_modeltester = ModelTester()
model_test = qt_modeltester.check(model)

Then I faced this error. HAS_QT_TESTER = hasattr(qt_api.QtTest, "QAbstractItemModelTester") AttributeError: '_QtApi' object has no attribute 'QtTest'

nicoddemus commented 4 months ago

Hi @slyin87,

pytest-qt is meant to be when writing tests, not for normal production code.

Try using it in a test:

def test(qtmodeltester):
    model = WorkNodeTreeModel()
    qt_modeltester.check(model)

Of course, you will need pytest and pytest-qt installed.

Closing for now, feel free to follow up with more questions.