NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #4289 most downloaded on PyPI
pytest support for PyQt and PySide applications
Last release 1 years ago
01 Jul 2025
Release timing varies
gaps range from 8 days to 1.5 years
Nearly every release is documented
notes for 43 of 47 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
48 releases · first in 2013
Added official support for Python 3.13.
Added official support for Python 3.13.
Dropped support for EOL Python 3.8.
Dropped support for EOL PySide 2.
Type annotations are now provided. Note that because the Qt library used is defined at runtime, Qt classes are currently annotated as Any.
Fixed PySide6 exceptions / warnings about being unable to disconnect signals with qtbot.waitSignal (#552, #558).
Reduced the likelyhood of trouble when using qtbot.waitSignal(s) and qtbot.waitCallback where the signal/callback is emitted from a non-main thread. In theory, more problems remain and this isn't a proper fix yet. In practice, it seems impossible to provoke any problems in pytest-qt's testsuite. (#586)
pluggy >=1.1 is now required: we now use new-style hook wrappers, which are less error prone.
One column per quarter.
pluggy >=1.1 is now required: we now use new-style hook wrappers, which are less error prone.
Fixed exception handling so they are properly cleared in Python 3.12, due to the new sys.last_exc attribute (#532).
Added official support for Python 3.12.
Added official support for Python 3.12.
Python 3.7 is no longer supported.
qapp now sets up the QApplication instance with a command line argument like this QApplication([prog_name]) instead of using an empty list QApplication([]). Here prog_name is the name of the app which defaults to pytest-qt-app, but can be redefined in the pytest.ini file, see qapp fixture. Alternatively, the arguments that will be passed to QApplication can be defined explicitly using the qapp_args fixture. This means that the default behavior of the qapp_args fixture 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).
Import the code sub-package from the correct location rather than the deprecated py package, restoring compatibility with pytest 7.2.0, where py was d…
Import the code sub-package from the correct location rather than the deprecated py package, restoring compatibility with pytest 7.2.0, where py was dropped. Thanks `@The-Compiler`_ for the PR.
Use pytest.hookimpl to configure hooks, avoiding a deprecation warning in pytest 7.2.0. Thanks `@The-Compiler`_ for the PR.
Now pytest-qt will check if any of the Qt libraries is already imported by the time the plugin loads, and use it if that is the case (#412). Thanks @eyllanesc for the PR.
Most custom pytest-qt exceptions can be accessed via qtbot (for example 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 ScreenshotError has been added to qtbot so it can be accessed in the same way (#460).
pytest-qt now requires Python 3.7+.
pytest-qt now requires Python 3.7+.
Improved PEP-8 aliases definition so they have a smaller call stack depth by one and better parameter suggestions in IDEs. (#383). Thanks @luziferius for the PR.
Updated model tester handling around hasChildren based on Qt's updates.
New qapp_cls fixture returning the QApplication class to use, thus making it easier to use a custom subclass without having to override the whole qapp fixture. 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.
New 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 shiboken2 project, used by pytest-qt 4.0.0. The dependency is now not needed any
Restored compatibility with PySide2 5.11, which doesn't depend on the shiboken2 project, used by pytest-qt 4.0.0. The dependency is now not needed anymore, and the .isdeleted attribute of qt_compat (which isn't intended for public use) is removed.
The sip module now gets imported directly if PyQt5.sip / PyQt6.sip wasn't found, as it's still packaged like that in some distributions (#369_). Thank
The sip module now gets imported directly if PyQt5.sip / PyQt6.sip wasn't found, as it's still packaged like that in some distributions (#369). Thanks `@The-Compiler`_ for the PR.
The qtbot.waitForWindowShown method is deprecated, as the underlying Qt method was obsoleted in Qt 5.0 and removed in Qt 6.0. Its name is imprecise an…
PySide6 and PyQt6 (6.1+) are now supported. Thanks @jensheilman and `@The-Compiler`_ for the PRs (#328, #330).
pytest-qt now requires Python 3.6+.
When using PyQt5, pytest-qt now requires PyQt5 5.11 or newer (#330).
Support for Qt4 (i.e. PyQt4 and PySide) is now dropped (#279).
The qtbot.waitActive and qtbot.waitExposed context managers are now available with all Qt APIs, rather than only PyQt5 (#361). Thanks `@The-Compiler`_ for the PR.
The qtbot.waitForWindowShown method 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.waitExposed context manager instead (#361). Thanks `@The-Compiler`_ for the PR.
The old qtbot.stopForInteraction() name is now removed as it was cumbersome and rarely used. Use qtbot.stop() (added in 1.1.1) instead (#306). Thanks `@The-Compiler`_ for the PR.
The old SignalTimeoutError exception alias is now removed, as it was renamed to TimeoutError in 2.1 (#306). Thanks `@The-Compiler`_ for the PR.
The old qt_wait_signal_raising option is now removed, as it was renamed to qt_default_raising in 3.1 (#306). Thanks `@The-Compiler`_ for the PR.
qtbot.waitSignal and waitSignals (as well as their PEP-8 aliases) supported passing None as 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 qtbot methods are now keyword-only (#366):
qtbot.waitActive: timeout (widget being the only positional argument)
qtbot.waitExposed: timeout (widget being the only positional argument)
qtbot.waitSignal: timeout, raising and check_params_cb (signal being the only positional argument)
qtbot.waitSignals: timeout, raising and check_params_cbs (signals being the only positional argument)
qtbot.assertNotEmitted: wait (signal being the only positional argument)
qtbot.waitUntil: timeout (callback being the only positional argument)
qtbot.waitCallback: timeout and 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.plugin anymore, and should instead be imported from the module they're residing in since the 1.6.0 release (#306):
pytestqt.plugin.QtBot -> pytestqt.qtbot.QtBot
pytestqt.plugin.SignalBlocker -> pytestqt.wait_signal.SignalBlocker
pytestqt.plugin.MultiSignalBlocker -> pytestqt.wait_signal.MultiSignalBlocker
pytestqt.plugin.Record -> pytestqt.logging.Record
pytestqt.plugin.capture_exceptions -> pytestqt.exceptions.capture_exceptions (but consider using qtbot.capture_exceptions instead)
pytestqt.plugin.format_captured_exceptions -> pytestqt.exceptions.format_captured_exceptions
The qt_api.extract_from_variant and qt_api.make_variant functions (which were never intended for public usage) as well as all class aliases (such as qt_api.QWidget or qt_api.QEvent, among others) are now removed. Thanks `@The-Compiler`_ for the PR.
The default timeouts for qtbot.waitSignal, waitSignals, waitUntil and waitCallback, waitActive and waitExposed have 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=1000 to those functions (#306). Thanks `@The-Compiler`_ for the PR.
waitUntil now raises a TimeoutError when a timeout occurs to make the cause of the timeout more explicit (#222). Thanks @karlch for the PR.
The QtTest::keySequence method is now exposed (if available, with Qt >= 5.10) (#289). Thanks `@The-Compiler`_ for the PR.
addWidget now enforces that its argument is a QWidget in order to display a clearer error when this isn't the case (#290). Thanks `@The-Compiler`_ for the PR.
New option qt_qapp_name can be used to set the name of the QApplication created by pytest-qt, defaulting to "pytest-qt-qapp" (#302). Thanks `@The-Compiler`_ for the PR.
When the -s (--capture=no) argument is passed to pytest, Qt log capturing is now disabled as well (#300). Thanks `@The-Compiler`_ for the PR.
PEP-8 aliases (add_widget, 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_compat module (such as an invalid PYTEST_QT_API setting 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_).
Improve message in uncaught exceptions by mentioning the Qt event loop instead of Qt virtual methods (#255).
pytest-qt now requires pytest version >= 3.0.
qtbot.addWiget now supports an optional before_close_func keyword-only argument, which if given is a function which is called before the widget is closed, with the widget as first argument.
Fix Off-by-one error in modeltester (#249_). Thanks @ext-jmmugnes_ for the PR.
Fix Off-by-one error in modeltester (#249). Thanks `@ext-jmmugnes`_ for the PR.
Fixed compatibility with PyQt5 5.11.3
Fixed compatibility with PyQt5 5.11.3
The CallbackBlocker returned by qtbot.waitCallback() now has a new assert_called_with(...) convenience method.
The CallbackBlocker returned by qtbot.waitCallback() now has a new assert_called_with(...) convenience method.
The qt_wait_signal_raising option was renamed to qt_default_raising. The old name continues to work, but is deprecated.
If Qt's model tester implemented in C++ is available (PyQt5 5.11 or newer), the qtmodeltester fixture now uses that instead of the Python implementation. This can be turned off by passing force_py=True to qtmodeltester.check().
The Python code used by qtmodeltester is now based on the latest Qt modeltester. This also means that the data_display_may_return_none attribute for qtmodeltester isn't used anymore.
New qtbot.waitCallback() method that returns a CallbackBlocker, which can be used to wait for a callback to be called.
qtbot.assertNotEmitted now has a new wait parameter which can be used to make sure asynchronous signals aren't emitted by waiting after the code in the with block finished.
The qt_wait_signal_raising option was renamed to qt_default_raising. The old name continues to work, but is deprecated.
The docs still referred to SignalTimeoutError in some places, despite it being renamed to TimeoutError in 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:0 line is shown anymore.
The no_qt_log marker is now registered with pytest so --strict can be used.
qtbot.waitSignal with timeout 0 now expects the signal to arrive directly in the code enclosed by it.
Thanks `@The-Compiler`_ for the PRs.
Another fix related to QtInfoMsg objects during logging (#225_).
Another fix related to QtInfoMsg objects during logging (`#225`_).
Fix handling of QtInfoMsg objects during logging (#225_). Thanks @willsALMANJ_ for the report.
Fix handling of QtInfoMsg objects during logging (#225). Thanks `@willsALMANJ`_ for the report.
Removed qtbot.mouseEvent proxy, it was an internal Qt function which has now been removed in PyQt 5.11 (#219_). Thanks @mitya57_ for the PR.
Properly handle chained exceptions when capturing them inside virtual methods (#215_). Thanks @fabioz_ for the report and sample code with the fix.
Properly handle chained exceptions when capturing them inside virtual methods (#215). Thanks `@fabioz`_ for the report and sample code with the fix.
Use new pytest 3.6 marker API when possible (#212_). Thanks @The-Compiler_ for the PR.
Use new pytest 3.6 marker API when possible (#212). Thanks `@The-Compiler`_ for the PR.
Fix QStringListModel import when using PySide2 (#209_). Thanks @rth_ for the PR.
Fix QStringListModel import when using PySide2 (#209). Thanks `@rth`_ for the PR.
PYTEST_QT_API environment variable correctly wins over qt_api ini variable if both are set at the same time (#196_). Thanks @mochick_ for the PR.
PYTEST_QT_API environment variable correctly wins over qt_api ini variable if both are set at the same time (#196). Thanks `@mochick`_ for the PR.
New qapp_args fixture which can be used to pass custom arguments to QApplication. Thanks @The-Compiler_ for the PR.
New qapp_args fixture which can be used to pass custom arguments to QApplication. Thanks `@The-Compiler`_ for the PR.
modeltester now accepts QBrush for BackgroundColorRole and TextColorRole (#189_). Thanks @p0las_ for the PR.
modeltester now accepts QBrush for BackgroundColorRole and TextColorRole (#189). Thanks `@p0las`_ for the PR.
pytest-qt now supports PySide2_ thanks to @rth_!
pytest-qt now supports PySide2 thanks to `@rth`_!
Fix issue where pytestqt was hiding the information when there's an exception raised from another exception on Python 3.
Fix issue where pytestqt was hiding the information when there's an exception raised from another exception on Python 3.
- Fixed tests on Python 3.6.
Fixed tests on Python 3.6.
Nothing published for this version
Nothing published for this version
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
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_raising ini option can be used to override the default value of the raising parameter of the qtbot.waitSignal and qtbot.waitSignals functions when omitted:
[pytest]
qt_wait_signal_raising = true
Calls which explicitly pass the raising parameter are not affected. Thanks `@The-Compiler`_ for idea and initial work on a PR (120).
qtbot now has a new assertNotEmitted context manager which can be used to ensure the given signal is not emitted (92). Thanks `@The-Compiler`_ for the PR!
SignalBlocker now has a args attribute with the arguments of the signal that triggered it, or None on a time out (115_). Thanks @billyshambrook_ for t
SignalBlocker now has a args attribute with the arguments of the signal that triggered it, or None on a time out (115). Thanks `@billyshambrook`_ for the request and `@The-Compiler`_ for the PR.
MultiSignalBlocker is now properly disconnects from signals upon exit.
Exception capturing now happens as early/late as possible in order to catch all possible exceptions (including fixtures)(105_). Thanks @The-Compiler_
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.addWidget are now closed before all other fixtures are tear down (106). Thanks `@The-Compiler`_ for request.
qtbot now has a new wait method which does a blocking wait while the event loop continues to run, similar to QTest::qWait. Thanks `@The-Compiler`_ for the PR (closes 107)!
raise RuntimeError instead of ImportError when 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).
pytest.mark.qt_log_ignore now supports an extend parameter that will extend the list of regexes used to ignore Qt messages (defaults to False). Thanks
pytest.mark.qt_log_ignore now supports an extend parameter 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-qt is properly tested with PyQt5 on Travis-CI. Many thanks to `@The-Compiler`_ for the PR!
PYTEST_QT_API can now be set to pyqt4v2 in order to use version 2 of the PyQt4 API. Thanks @montefra_ for the PR (93_)!
PYTEST_QT_API can now be set to pyqt4v2 in order to use version 2 of the PyQt4 API. Thanks `@montefra`_ for the PR (93)!
Reduced verbosity when exceptions are captured in virtual methods (77_, thanks @The-Compiler_).
Reduced verbosity when exceptions are captured in virtual methods (77, thanks `@The-Compiler`_).
pytestqt.plugin has been split in several files (74) and tests have been moved out of the pytestqt package. 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).
Exceptions are now captured also during test tear down, as delayed events will get processed then and might raise exceptions in virtual methods; this
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).
Fixed log line number in messages, and provide better contextual information in Qt5 (#55, thanks @The-Compiler);
waitSignals or waitSignal with-statement block would be swallowed and a SignalTimeoutError would be raised instead. (#59, thanks @The-Compiler for bringing up the issue and providing a test case);qapp fixture would return None. Thanks to @gqmelo for noticing and providing a PR;qtlog now sports a context manager method, disabled (#58). Thanks @The-Compiler for the idea and testing;Messages sent by qDebug, qWarning, qCritical are captured and displayed when tests fail, similar to pytest-catchlog. Also, tests can be configured to
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).waitSignals: will block untill all signals given are triggered, see docs (thanks @The-Compiler for idea and complete PR).raising to waitSignals and waitSignals: when True (defaults to False) will raise a qtbot.SignalTimeoutError exception when timeout is reached, see docs (thanks again to @The-Compiler for idea and complete PR).pytest-qt now requires pytest version >= 2.7.QApplication.exit() is no longer called at the end of the test session and the QApplication instance is not garbage collected anymore;QtBot no longer receives a QApplication as a parameter in the constructor, always referencing QApplication.instance() now; this avoids keeping an extra reference in the qtbot instances.deleteLater is called on widgets added in QtBot.addWidget at the end of each test;QApplication.processEvents() is called at the end of each test to make sure widgets are cleaned up;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.
New method waitSignals: will block until all signals given are triggered (thanks `@The-Compiler`_ for idea and complete PR).
New parameter raising to waitSignals and waitSignals: when True will raise a qtbot.SignalTimeoutError exception when timeout is reached (defaults to False). (thanks again to `@The-Compiler`_ for idea and complete PR).
pytest-qt now requires pytest version >= 2.7.
QApplication.exit() is no longer called at the end of the test session and the QApplication instance is not garbage collected anymore;
QtBot no longer receives a QApplication as a parameter in the constructor, always referencing QApplication.instance() now; this avoids keeping an extra reference in the qtbot instances.
deleteLater is called on widgets added in QtBot.addWidget at the end of each test;
QApplication.processEvents() is called at the end of each test to make sure widgets are cleaned up;
Which Qt api will be used is still detected automatically, but you can choose one using the PYTEST_QT_API environment variable (the old PYTEST_QT_FORC
pytest-qt now supports PyQt5!
Which Qt api will be used is still detected automatically, but you can choose one using the PYTEST_QT_API environment variable (the old PYTEST_QT_FORCE_PYQT is still supported for backward compatibility).
Many thanks to @jdreaver for helping to test this release!
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.
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.
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.
Now it is possible to disable automatic exception capture by using markers or a pytest.ini option. Consult the documentation for more information. (#2
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)Fixed #16: a signal emitted immediately inside a waitSignal block now works as expected (thanks @baudren)
waitSignal block now works as expected (thanks @baudren)This version include the new waitSignal function, which makes it easy to write tests for long running computations that happen in other threads or pro
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)
Nothing published for this version
Added stop as an alias for stopForInteraction (#10, thanks @itghisi)
stop as an alias for stopForInteraction (#10, thanks @itghisi)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!
QtBot: it was not being rendered in the docs due to an import error.This release adds support for Python 3+.
This release adds support for Python 3+.
This is just a minor release with some documentation improvements.
This is just a minor release with some documentation improvements.
Small bug fix release.
Small bug fix release.
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →