Changelog¶
1.11.0¶
Note
The default value for raising is planned to change to True starting in
pytest-qt version 1.12. Users wishing to preserve
the current behavior (raising is False by default) should make
use of the new qt_wait_signal_raising ini option below.
New
qt_wait_signal_raisingini option can be used to override the default value of theraisingparameter of theqtbot.waitSignalandqtbot.waitSignalsfunctions when omitted:[pytest] qt_wait_signal_raising = true
Calls which explicitly pass the
raisingparameter are not affected. Thanks @The-Compiler for idea and initial work on a PR (120).qtbotnow has a newassertNotEmittedcontext manager which can be used to ensure the given signal is not emitted (92). Thanks @The-Compiler for the PR!
1.10.0¶
SignalBlockernow has aargsattribute with the arguments of the signal that triggered it, orNoneon a time out (115). Thanks @billyshambrook for the request and @The-Compiler for the PR.MultiSignalBlockeris now properly disconnects from signals upon exit.
1.9.0¶
- Exception capturing now happens as early/late as possible in order to catch all possible exceptions (including fixtures)(105). Thanks @The-Compiler for the request.
- Widgets registered by
qtbot.addWidgetare now closed before all other fixtures are tear down (106). Thanks @The-Compiler for request. qtbotnow has a newwaitmethod which does a blocking wait while the event loop continues to run, similar toQTest::qWait. Thanks @The-Compiler for the PR (closes 107)!- raise
RuntimeErrorinstead ofImportErrorwhen failing to import any Qt binding: raising the latter causes pluggy in pytest-2.8 to generate a subtle warning instead of a full blown error. Thanks @Sheeo for bringing this problem to attention (closes 109).
1.8.0¶
pytest.mark.qt_log_ignorenow supports anextendparameter that will extend the list of regexes used to ignore Qt messages (defaults to False). Thanks @The-Compiler for the PR (99).- Fixed internal error when interacting with other plugins that raise an error, hiding the original exception (98). Thanks @The-Compiler for the PR!
- Now
pytest-qtis properly tested with PyQt5 on Travis-CI. Many thanks to @The-Compiler for the PR!
1.7.0¶
1.6.0¶
- Reduced verbosity when exceptions are captured in virtual methods (77, thanks @The-Compiler).
pytestqt.pluginhas been split in several files (74) and tests have been moved out of thepytestqtpackage. This should not affect users, but it is worth mentioning nonetheless.QApplication.processEvents()is now called before and after other fixtures and teardown hooks, to better try to avoid non-processed events from leaking from one test to the next. (67, thanks @The-Compiler).- Show Qt/PyQt/PySide versions in pytest header (68, thanks @The-Compiler!).
- Disconnect SignalBlocker functions after its loop exits to ensure second emissions that call the internal functions on the now-garbage-collected SignalBlocker instance (#69, thanks @The-Compiler for the PR).
1.5.1¶
- 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 callabortby default, which will crash the interpreter. (65, thanks @The-Compiler).
1.5.0¶
- Fixed log line number in messages, and provide better contextual information in Qt5 (55, thanks @The-Compiler);
- Fixed issue where exceptions inside a
waitSignalsorwaitSignalwith-statement block would be swallowed and aSignalTimeoutErrorwould be raised instead. (59, thanks @The-Compiler for bringing up the issue and providing a test case); - Fixed issue where the first usage of
qappfixture would returnNone. Thanks to @gqmelo for noticing and providing a PR; - New
qtlognow sports a context manager method,disabled(58). Thanks @The-Compiler for the idea and testing;
1.4.0¶
- Messages sent by
qDebug,qWarning,qCriticalare captured and displayed when tests fail, similar to pytest-catchlog. Also, tests can be configured to automatically fail if an unexpected message is generated. - New method
waitSignals: will block untill all signals given are triggered (thanks @The-Compiler for idea and complete PR). - New parameter
raisingtowaitSignalsandwaitSignals: whenTruewill raise aqtbot.SignalTimeoutErrorexception when timeout is reached (defaults toFalse). (thanks again to @The-Compiler for idea and complete PR). pytest-qtnow requirespytestversion >= 2.7.
Internal changes to improve memory management¶
QApplication.exit()is no longer called at the end of the test session and theQApplicationinstance is not garbage collected anymore;QtBotno longer receives a QApplication as a parameter in the constructor, always referencingQApplication.instance()now; this avoids keeping an extra reference in theqtbotinstances.deleteLateris called on widgets added inQtBot.addWidgetat the end of each test;QApplication.processEvents()is called at the end of each test to make sure widgets are cleaned up;
1.3.0¶
1.2.3¶
- Now the module
``qt_compat``no longer setsQStringandQVariantAPIs to2for PyQt, making it compatible for those still using version1of the API.
1.2.2¶
- Now it is possible to disable automatic exception capture by using markers or
a
pytest.inioption. Consult the documentation for more information. (26, thanks @datalyze-solutions for bringing this up). QApplicationinstance is created only if it wasn’t created yet (21, thanks @fabioz!)addWidgetnow keeps a weak reference its widgets (20, thanks @fabioz)
1.2.1¶
1.2.0¶
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)
1.1.1¶
Added
stopas an alias forstopForInteraction(10, thanks @itghisi)Now exceptions raised in virtual methods make tests fail, instead of silently passing (11). If an exception is raised, the test will fail and it exceptions that happened inside virtual calls will be printed as such:
E Failed: Qt exceptions in virtual methods: E ________________________________________________________________________________ E File "x:\pytest-qt\pytestqt\_tests\test_exceptions.py", line 14, in event E raise ValueError('mistakes were made') E E ValueError: mistakes were made E ________________________________________________________________________________ E File "x:\pytest-qt\pytestqt\_tests\test_exceptions.py", line 14, in event E raise ValueError('mistakes were made') E E ValueError: mistakes were made E ________________________________________________________________________________Thanks to @jdreaver for request and sample code!
Fixed documentation for
QtBot: it was not being rendered in the docs due to an import error.
1.1.0¶
Python 3 support.
1.0.2¶
Minor documentation fixes.
1.0.1¶
Small bug fix release.
1.0.0¶
First working version.