[PyQt] QML test with component defined in Python

Cody Scott cody at perspexis.com
Thu Jan 19 14:10:17 GMT 2017

I'm trying to write a test in QML using QtTest that tests a QML component
defined in Python using QtQml.qmlRegisterType().

It appears that the PyQt5==5.7.1 wheel is missing the correct files for

Here is an example of what I am trying to do

This gist is the same as the attached file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170119/9e4715f3/attachment.html>
-------------- next part --------------
#!/usr/bin/env python
import sys

from PyQt5 import Qt, QtCore, QtGui, QtQml, QtWidgets

class OutputType(QtCore.QObject):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.output = ""

    def ChangeOutput(self):
        self.output = "Hello"

QML = b"""
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtTest 1.1

import OutputType 1.0

Item {
    width: 800
    height: 600
    visible: true

    OutputType {
        id: outputType

    Text {
        id: txt
        text: outputType.output
    Button {
        id: btn
        onClicked: {
    TestCase {
      name: "MouseTests"
      function test_clicked(){
          compare(txt.text, "")
          compare(txt.text, "Hello")

app = QtWidgets.QApplication(sys.argv + ["-nograb"])
QtQml.qmlRegisterType(OutputType, 'OutputType', 1, 0, 'OutputType')
engine = QtQml.QQmlApplicationEngine()

More information about the PyQt mailing list