qappnow sets up the
QApplicationinstance with a command line argument like this
QApplication([prog_name])instead of using an empty list
prog_nameis the name of the app which defaults to
pytest-qt-app, but can be redefined in the
pytest.inifile, see qapp fixture. Alternatively, the arguments that will be passed to
QApplicationcan be defined explicitly using the
qapp_argsfixture. This means that the default behavior of the
qapp_argsfixture is now also changed accordingly: it now returns the list
[prog_name]instead of an empty list. Thanks to @The-Compiler (#483) and @hakonhagland (#515).
codesub-package from the correct location rather than the deprecated
pypackage, restoring compatibility with pytest 7.2.0, where
pywas dropped. Thanks @The-Compiler for the PR.
pytest.hookimplto configure hooks, avoiding a deprecation warning in pytest 7.2.0. Thanks @The-Compiler for the PR.
pytest-qtexceptions can be accessed via
qtbot.TimeoutError), but it was not always explicit in the documentation that this is the recommended way to access those exceptions, instead of importing them from
pytestqt.exceptions. This is now clarified in the documentation and examples, and an alias to
ScreenshotErrorhas been added to
qtbotso it can be accessed in the same way (#460).
pytest-qtnow requires Python 3.7+.
Updated model tester handling around
hasChildrenbased on Qt’s updates.
qapp_clsfixture returning the
QApplicationclass to use, thus making it easier to use a custom subclass without having to override the whole
qappfixture. Thanks @The-Compiler for the PR.
Updated model tester to track/verify in-flight changes based on Qt’s updates. Thanks @The-Compiler for the PR.
qtbot.screenshot()method which can be used to take a screenshot of the given widget. Thanks @The-Compiler for the PR.
Restored compatibility with PySide2 5.11, which doesn’t depend on the
shiboken2project, used by pytest-qt 4.0.0. The dependency is now not needed anymore, and the
qt_compat(which isn’t intended for public use) is removed.
pytest-qtnow requires Python 3.6+.
When using PyQt5,
pytest-qtnow requires PyQt5 5.11 or newer (#330).
Support for Qt4 (i.e.
PySide) is now dropped (#279).
qtbot.waitForWindowShownmethod is deprecated, as the underlying Qt method was obsoleted in Qt 5.0 and removed in Qt 6.0. Its name is imprecise and the pytest-qt wrapper does not raise TimeoutError if the window wasn’t shown. Please use the
qtbot.waitExposedcontext manager instead (#361). Thanks @The-Compiler for the PR.
waitSignals(as well as their PEP-8 aliases) supported passing
Noneas signal, making them wait for the given timeout instead. This is not supported anymore, use
qtbot.wait(ms)instead (#306). Thanks @The-Compiler for the PR.
Various arguments to
qtbotmethods are now keyword-only (#366):
widgetbeing the only positional argument)
widgetbeing the only positional argument)
signalbeing the only positional argument)
signalsbeing the only positional argument)
signalbeing the only positional argument)
callbackbeing the only positional argument)
raising(with no positional arguments)
The same applies to the respective PEP-8 aliases. Thanks @The-Compiler for the PR.
Various classes are now not importable from
pytestqt.pluginanymore, and should instead be imported from the module they’re residing in since the 1.6.0 release (#306):
pytestqt.exceptions.capture_exceptions(but consider using
qt_api.make_variantfunctions (which were never intended for public usage) as well as all class aliases (such as
qt_api.QEvent, among others) are now removed. Thanks @The-Compiler for the PR.
The default timeouts for
waitExposedhave been raised from 1s to 5s. This makes them in line the default timeout used by Qt’s underlying methods such as
QSignalSpy::wait. To get the old behavior back, explicitly pass
timeout=1000to those functions (#306). Thanks @The-Compiler for the PR.
PEP-8 aliases (
wait_active, etc) are no longer just simple assignments to the methods, but they are real methods which call the normal implementations. This makes subclasses work as expected, instead of having to duplicate the assignment (#326, #333). Thanks @oliveira-mauricio and @jensheilman for the PRs.
Errors related to the
qt_compatmodule (such as an invalid
PYTEST_QT_APIsetting or missing Qt API wrappers) are now shown as a more human-readable error message rather than an internal pytest error (#355). Thanks @The-Compiler for the PR.
Improve message in uncaught exceptions by mentioning the Qt event loop instead of Qt virtual methods (#255).
pytestversion >= 3.0.
qtbot.addWigetnow supports an optional
before_close_funckeyword-only argument, which if given is a function which is called before the widget is closed, with the widget as first argument.
Fixed compatibility with PyQt5 5.11.3
qtbot.waitCallback()now has a new
If Qt’s model tester implemented in C++ is available (PyQt5 5.11 or newer), the
qtmodeltesterfixture now uses that instead of the Python implementation. This can be turned off by passing
The Python code used by
qtmodeltesteris now based on the latest Qt modeltester. This also means that the
qtmodeltesterisn’t used anymore.
qtbot.waitCallback()method that returns a
CallbackBlocker, which can be used to wait for a callback to be called.
qtbot.assertNotEmittednow has a new
waitparameter which can be used to make sure asynchronous signals aren’t emitted by waiting after the code in the
qt_wait_signal_raisingoption was renamed to
qt_default_raising. The old name continues to work, but is deprecated.
The docs still referred to
SignalTimeoutErrorin some places, despite it being renamed to
TimeoutErrorin the 2.1 release. This is now corrected.
Improve debugging output when no Qt wrapper was found.
When no context is available for warnings on Qt 5, no
None:None:0line is shown anymore.
no_qt_logmarker is now registered with pytest so
--strictcan be used.
0now expects the signal to arrive directly in the code enclosed by it.
Thanks @The-Compiler for the PRs.
Another fix related to
QtInfoMsgobjects during logging (#225).
qapp_argsfixture which can be used to pass custom arguments to
QApplication. Thanks @The-Compiler for the PR.
Fix issue where
pytestqtwas hiding the information when there’s an exception raised from another exception on Python 3.
Fixed tests on Python 3.6.
SignalTimeoutErrorhas been renamed to
SignalTimeoutErroris kept as a backward compatibility alias.
pytest-qt 2.0, we changed some defaults to values we think are much
better, however this required some backwards-incompatible changes:
pytest-qtnow defaults to using
PYTEST_QT_APIis not set. Before, it preferred
PySidewhich is using the discontinued Qt4.
Python 3 versions prior to 3.4 are no longer supported.
@pytest.mark.qt_log_ignoremark now defaults to
extend=True, i.e. extends the patterns defined in the config file rather than overriding them. You can pass
extend=Falseto get the old behaviour of overriding the patterns.
qtbot.waitSignalnow defaults to
raising=Trueand raises an exception on timeouts. You can set
qt_wait_signal_raising = falsein your config to get back the old behaviour.
PYTEST_QT_FORCE_PYQTenvironment variable is no longer supported. Set
PYTEST_QT_APIto the appropriate value instead or the new
qt_apiconfiguration option in your
From this version onward,
pytest-qtis licensed under the MIT license (#134).
qtbot.waitUntilmethod, which continuously calls a callback until a condition is met or a timeout is reached. Useful for testing asynchronous features (like in X window environments for example).
waitSignalscan receive an optional callback (or list of callbacks) that can evaluate if the arguments of emitted signals should resume execution or not. Additionally
waitSignalshas a new
orderparameter that allows to expect signals and their arguments in a strict, semi-strict or no specific order. Thanks @MShekow for the PR (#141).
pytestqt.qt_compatis an internal module and shouldn’t be imported directly, it is known that some test suites did import it. This module now uses a lazy-load mechanism to load Qt classes and objects, so the old symbols (
QApplication, etc.) are no longer available from it.
The default value for
raising is planned to change to
True starting in
1.12. Users wishing to preserve
the current behavior (
False by default) should make
use of the new
qt_wait_signal_raising ini option below.
qt_wait_signal_raisingini option can be used to override the default value of the
raisingparameter of the
qtbot.waitSignalsfunctions when omitted:
[pytest] qt_wait_signal_raising = true
ImportErrorwhen failing to import any Qt binding: raising the latter causes
pytest-2.8to generate a subtle warning instead of a full blown error. Thanks @Sheeo for bringing this problem to attention (closes 109).
pytest-qtis properly tested with PyQt5 on Travis-CI. Many thanks to @The-Compiler for the PR!
pytestqt.pluginhas been split in several files (74) and tests have been moved out of the
pytestqtpackage. 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).
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).
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
abortby default, which will crash the interpreter. (65, thanks @The-Compiler).
Fixed issue where exceptions inside a
waitSignalwith-statement block would be swallowed and a
SignalTimeoutErrorwould 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 return
None. Thanks to @gqmelo for noticing and providing a PR;
Messages sent by
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.
waitSignals: will block until all signals given are triggered (thanks @The-Compiler for idea and complete PR).
Truewill raise a
qtbot.SignalTimeoutErrorexception when timeout is reached (defaults to
False). (thanks again to @The-Compiler for idea and complete PR).
pytestversion >= 2.7.
Internal changes to improve memory management
QApplication.exit()is no longer called at the end of the test session and the
QApplicationinstance is not garbage collected anymore;
QtBotno longer receives a QApplication as a parameter in the constructor, always referencing
QApplication.instance()now; this avoids keeping an extra reference in the
deleteLateris called on widgets added in
QtBot.addWidgetat the end of each test;
QApplication.processEvents()is called at the end of each test to make sure widgets are cleaned up;
Now the module
``qt_compat``no longer sets
2for PyQt, making it compatible for those still using version
1of the API.
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).
This version include the new
waitSignal function, which makes it easy
to write tests for long running computations that happen in other threads
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)
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.
Python 3 support.
Minor documentation fixes.
Small bug fix release.
First working version.