Releases: pytest-dev/pytest-qt
Releases · pytest-dev/pytest-qt
4.4.0
4.3.1
Use an environment for deploy
Capturing exceptions during test tear down
Exceptions are now captured also during test tear down, as delayed events will get processed then and might raise exceptions in virtual methods; this is specially problematic in PyQt5.5
, which changed the behavior to call abort
by default, which will crash the interpreter. (#65, thanks @The-Compiler).
qtlog.disabled() and some bug fixes
- Fixed log line number in messages, and provide better contextual information in Qt5 (#55, thanks @The-Compiler);
- Fixed issue where exceptions inside a
waitSignals
orwaitSignal
with-statement block would be swallowed and aSignalTimeoutError
would be raised instead. (#59, thanks @The-Compiler for bringing up the issue and providing a test case); - Fixed issue where the first usage of
qapp
fixture would returnNone
. Thanks to @gqmelo for noticing and providing a PR; - New
qtlog
now sports a context manager method,disabled
(#58). Thanks @The-Compiler for the idea and testing;
Qt Logging, waitSignals
- Messages sent by
qDebug
,qWarning
,qCritical
are captured and displayed when tests fail, similar to pytest-catchlog. Also, tests can be configured to automatically fail if an unexpected message is generated. (See docs). - New method
waitSignals
: will block untill all signals given are triggered, see docs (thanks @The-Compiler for idea and complete PR). - New parameter
raising
towaitSignals
andwaitSignals
: whenTrue
(defaults toFalse
) will raise aqtbot.SignalTimeoutError
exception when timeout is reached, see docs (thanks again to @The-Compiler for idea and complete PR). pytest-qt
now requirespytest
version >= 2.7.
Internal changes to improve memory management
QApplication.exit()
is no longer called at the end of the test session and theQApplication
instance is not garbage collected anymore;QtBot
no longer receives a QApplication as a parameter in the constructor, always referencingQApplication.instance()
now; this avoids keeping an extra reference in theqtbot
instances.deleteLater
is called on widgets added inQtBot.addWidget
at the end of each test;QApplication.processEvents()
is called at the end of each test to make sure widgets are cleaned up;
PyQt5 support
PyQt: no longer setting API version
Now the module qt_compat
no longer sets QString
and QVariant
apis to 2
for PyQt, making it compatible for those still using version 1
of the API.
Small improvements
- Now it is possible to disable automatic exception capture by using markers or a
pytest.ini
option. Consult the documentation for more information. (#26, thanks @datalyze-solutions for bringing this up) QApplication
instance is created only if it wasn't created yet (#21, thanks @fabioz!)addWidget
now keeps a weak reference its widgets (#20, thanks @fabioz)
Bug fix
waitSignal support added
This version include the new waitSignal
function, which makes it easy to write tests for long running computations that happen in other threads or processes:
def test_long_computation(qtbot):
app = Application()
# Watch for the app.worker.finished signal, then start the worker.
with qtbot.waitSignal(app.worker.finished, timeout=10000) as blocker:
blocker.connect(app.worker.failed) # Can add other signals to blocker
app.worker.start()
# Test will wait here until either signal is emitted, or 10 seconds has elapsed
assert blocker.signal_triggered # Assuming the work took less than 10 seconds
assert_application_results(app)
Many thanks to @jdreaver for discussion and complete PR! (#12, #13)