[PyQt] Problem with QTest
Antonio Valentino
antonio.valentino at tiscali.it
Wed Dec 31 08:44:28 GMT 2014
Hi list,
I'm making some experiment with QTest and I encountered a problem.
The following test fails
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from PyQt5 import QtWidgets
from PyQt5.QtTest import QTest
class TestCase(unittest.TestCase):
def setUp(self):
self.w = QtWidgets.QSpinBox()
self.w.setValue(12) # <-- commenting this line all works fine
def test_value(self):
value = 34
QTest.keyClicks(self.w, str(value))
self.assertEqual(self.w.value(), value)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
unittest.main()
"""
Output:
"""
======================================================================
FAIL: test_value (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "qtestexample3.py", line 18, in test_value
self.assertEqual(self.w.value(), value)
AssertionError: 12 != 34
----------------------------------------------------------------------
Ran 1 test in 0.051s
FAILED (failures=1)
"""
It is not clear to me why it happens.
Also the test pass as expected if I remove the initialization line:
self.w.setValue(12)
I also made some attempt to use QTest.qWaitForWindowActive,
QTest.qWaitForWindowExposed and also processEvents, but nothing changes.
Does anybody have an idea about what is the problem?
best regards
--
Antonio Valentino
More information about the PyQt
mailing list