Table Of Contents

QTest

Synopsis

Static functions

Detailed Description

The QTest namespace contains all the functions and declarations that are related to the QTestLib tool.

Please refer to the QTestLib Manual documentation for information on how to write unit tests.

PySide.QtTest.QTest.LogElementType

The enum specifies the kinds of test log messages.

Constant Description
QTest.LET_Undefined  
QTest.LET_Property  
QTest.LET_Properties  
QTest.LET_Failure  
QTest.LET_Error  
QTest.LET_TestCase  
QTest.LET_TestSuite  
QTest.LET_Benchmark  
QTest.LET_SystemError  

Note

This enum was introduced or modified in Qt 4.6

PySide.QtTest.QTest.AttributeIndex

This enum numbers the different tests.

Constant Description
QTest.AI_Undefined  
QTest.AI_Name  
QTest.AI_Result  
QTest.AI_Tests  
QTest.AI_Failures  
QTest.AI_Errors  
QTest.AI_Type  
QTest.AI_Description  
QTest.AI_PropertyValue  
QTest.AI_QTestVersion  
QTest.AI_QtVersion  
QTest.AI_File  
QTest.AI_Line  
QTest.AI_Metric  
QTest.AI_Tag  
QTest.AI_Value  
QTest.AI_Iterations  

Note

This enum was introduced or modified in Qt 4.6

PySide.QtTest.QTest.QBenchmarkMetric

This enum lists all the things that can be benchmarked.

Constant Description
QTest.FramesPerSecond Frames per second
QTest.BitsPerSecond Bits per second
QTest.BytesPerSecond Bytes per second
QTest.WalltimeMilliseconds Clock time in milliseconds
QTest.CPUTicks CPU time
QTest.InstructionReads Instruction reads
QTest.Events Event count

See also

QTest.benchmarkMetricName() QTest.benchmarkMetricUnit()

Note

This enum was introduced or modified in Qt 4.7

PySide.QtTest.QTest.TestFailMode

This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros.

Constant Description
QTest.Abort Aborts the execution of the test. Use this mode when it doesn’t make sense to execute the test any further after the expected failure.
QTest.Continue Continues execution of the test after the expected failure.

See also

QEXPECT_FAIL()

PySide.QtTest.QTest.MouseAction

This enum describes possible actions for mouse handling.

Constant Description
QTest.MousePress A mouse button is pressed.
QTest.MouseRelease A mouse button is released.
QTest.MouseClick A mouse button is clicked (pressed and released).
QTest.MouseDClick A mouse button is double clicked (pressed and released twice).
QTest.MouseMove The mouse pointer has moved.
PySide.QtTest.QTest.SkipMode

This enum describes the modes for skipping tests during execution of the test data.

Constant Description
QTest.SkipSingle Skips the current entry in the test table; continues execution of all the other entries in the table.
QTest.SkipAll Skips all the entries in the test table; the test won’t be executed further.

See also

QSKIP()

PySide.QtTest.QTest.KeyAction

This enum describes possible actions for key handling.

Constant Description
QTest.Press The key is pressed.
QTest.Release The key is released.
QTest.Click The key is clicked (pressed and released).
static PySide.QtTest.QTest.addColumnInternal(id, name)
Parameters:
  • idPySide.QtCore.int
  • name – str
static PySide.QtTest.QTest.asciiToKey(ascii)
Parameters:asciiPySide.QtCore.char
Return type:PySide.QtCore.Qt.Key

Convert an ascii char key value to a Qt Key value. If the key is unknown a 0 is returned.

Note: this may happen more than you like since not all known ascii keys _are_ converted already. So feel free to add all the keys you need.

static PySide.QtTest.QTest.compare_ptr_helper(t1, t2, actual, expected, file, line)
Parameters:
  • t1void
  • t2void
  • actual – str
  • expected – str
  • file – str
  • linePySide.QtCore.int
Return type:

PySide.QtCore.bool

static PySide.QtTest.QTest.compare_string_helper(t1, t2, actual, expected, file, line)
Parameters:
  • t1 – str
  • t2 – str
  • actual – str
  • expected – str
  • file – str
  • linePySide.QtCore.int
Return type:

PySide.QtCore.bool

static PySide.QtTest.QTest.currentDataTag()
Return type:str

Returns the name of the current test data. If the test doesn’t have any assigned testdata, the function returns 0.

static PySide.QtTest.QTest.currentTestFailed()
Return type:PySide.QtCore.bool

Returns true if the current test function failed, otherwise false.

static PySide.QtTest.QTest.currentTestFunction()
Return type:str

Returns the name of the test function that is currently executed.

Example:

void MyTestClass.cleanup()
{
    if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
        // clean up all database connections
        closeAllDatabases()
    }
}
static PySide.QtTest.QTest.ignoreMessage(type, message)
Parameters:
  • typePySide.QtCore.QtMsgType
  • message – str

Ignores messages created by qDebug() or qWarning() . If the message with the corresponding type is outputted, it will be removed from the test log. If the test finished and the message was not outputted, a test failure is appended to the test log.

Note

Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call PySide.QtTest.QTest.ignoreMessage() twice, too.

Example:

QDir dir

QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)")
dir.mkdir("")

The example above tests that QDir.mkdir() outputs the right warning when invoked with an invalid file name.

static PySide.QtTest.QTest.keyClick(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.char
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyClick(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.Qt.Key
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyClicks(widget, sequence[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • sequence – unicode
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyEvent(action, widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
static PySide.QtTest.QTest.keyEvent(action, widget, ascii[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
static PySide.QtTest.QTest.keyPress(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.Qt.Key
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyPress(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.char
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyRelease(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.Qt.Key
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyRelease(widget, key[, modifier=Qt.NoModifier[, delay=-1]])
Parameters:
  • widgetPySide.QtGui.QWidget
  • keyPySide.QtCore.char
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.keyToAscii(key)
Parameters:keyPySide.QtCore.Qt.Key
Return type:PySide.QtCore.char
static PySide.QtTest.QTest.mouseClick(widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
Parameters:
static PySide.QtTest.QTest.mouseDClick(widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
Parameters:
static PySide.QtTest.QTest.mouseEvent(action, widget, button, stateKey, pos[, delay=-1])
Parameters:
static PySide.QtTest.QTest.mouseMove(widget[, pos=QPoint()[, delay=-1]])
Parameters:

Moves the mouse pointer to a widget . If pos is not specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

static PySide.QtTest.QTest.mousePress(widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
Parameters:
static PySide.QtTest.QTest.mouseRelease(widget, button[, stateKey=0[, pos=QPoint()[, delay=-1]]])
Parameters:
static PySide.QtTest.QTest.qElementData(elementName, metaTypeId)
Parameters:
  • elementName – str
  • metaTypeIdPySide.QtCore.int
Return type:

void

static PySide.QtTest.QTest.qExpectFail(dataIndex, comment, mode, file, line)
Parameters:
Return type:

PySide.QtCore.bool

static PySide.QtTest.QTest.qGlobalData(tagName, typeId)
Parameters:
  • tagName – str
  • typeIdPySide.QtCore.int
Return type:

void

static PySide.QtTest.QTest.qSkip(message, mode, file, line)
Parameters:
static PySide.QtTest.QTest.qWaitForWindowShown(window)
Parameters:windowPySide.QtGui.QWidget
Return type:PySide.QtCore.bool

Waits until the window is shown in the screen. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Returns true.

Example:

widget = QWidget()
widget.show()
QTest.qWaitForWindowShown(widget)
static PySide.QtTest.QTest.sendKeyEvent(action, widget, code, ascii, modifier[, delay=-1])
Parameters:
static PySide.QtTest.QTest.sendKeyEvent(action, widget, code, text, modifier[, delay=-1])
Parameters:
static PySide.QtTest.QTest.setBenchmarkResult(result, metric)
Parameters:

Sets the benchmark result for this test function to result .

Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use metric to specify how QTestLib should interpret the results.

The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the earlier reported results.

Note that the -iterations command line argument has no effect on test functions without the QBENCHMARK macro.

static PySide.QtTest.QTest.simulateEvent(widget, press, code, modifier, text, repeat[, delay=-1])
Parameters:
  • widgetPySide.QtGui.QWidget
  • pressPySide.QtCore.bool
  • codePySide.QtCore.int
  • modifierPySide.QtCore.Qt.KeyboardModifiers
  • text – unicode
  • repeatPySide.QtCore.bool
  • delayPySide.QtCore.int
static PySide.QtTest.QTest.testObject()
Return type:PySide.QtCore.QObject
static PySide.QtTest.QTest.touchEvent([widget=None[, deviceType=QTouchEvent.TouchScreen]])
Parameters:
Return type:

PySide.QtTest.QTouchEventSequence