- New
qapp_args
fixture which can be used to pass custom arguments toQApplication
. Thanks @The-Compiler for the PR.
modeltester
now acceptsQBrush
forBackgroundColorRole
andTextColorRole
(#189). Thanks @p0las for the PR.
- 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.
waitSignal
andwaitSignals
now provide much more detailed messages when expected signals are not emitted. Many thanks to @MShekow for the PR (#153).qtbot
fixture now can capture Qt virtual method exceptions in a block usingcaptureExceptions
(#154). Thanks to @fogo for the PR.- New qtbot.waitActive and qtbot.waitExposed methods for PyQt5. Thanks @The-Compiler for the request (#158).
SignalTimeoutError
has been renamed toTimeoutError
.SignalTimeoutError
is kept as a backward compatibility alias.
With pytest-qt
2.0, we changed some defaults to values we think are much
better, however this required some backwards-incompatible changes:
pytest-qt
now defaults to usingPyQt5
ifPYTEST_QT_API
is not set. Before, it preferredPySide
which is using the discontinued Qt4.- Python 3 versions prior to 3.4 are no longer supported.
- The
@pytest.mark.qt_log_ignore
mark now defaults toextend=True
, i.e. extends the patterns defined in the config file rather than overriding them. You can passextend=False
to get the old behaviour of overriding the patterns. qtbot.waitSignal
now defaults toraising=True
and raises an exception on timeouts. You can setqt_wait_signal_raising = false
in your config to get back the old behaviour.PYTEST_QT_FORCE_PYQT
environment variable is no longer supported. SetPYTEST_QT_API
to the appropriate value instead or the newqt_api
configuration option in yourpytest.ini
file.
- From this version onward,
pytest-qt
is licensed under the MIT license (#134). - New
qtmodeltester
fixture to testQAbstractItemModel
subclasses. Thanks @The-Compiler for the initiative and port of the original C++ code for ModelTester (#63). - New
qtbot.waitUntil
method, 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). waitSignal
andwaitSignals
can receive an optional callback (or list of callbacks) that can evaluate if the arguments of emitted signals should resume execution or not. AdditionallywaitSignals
has a neworder
parameter that allows to expect signals and their arguments in a strict, semi-strict or no specific order. Thanks @MShekow for the PR (#141).- Now which Qt binding
pytest-qt
will use can be configured by theqt_api
config option. Thanks @The-Compiler for the request (#129). - While
pytestqt.qt_compat
is 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 (QtCore
,QApplication
, etc.) are no longer available from it.
- Exceptions caught by
pytest-qt
insys.excepthook
are now also printed tostderr
, making debugging them easier from within an IDE. Thanks @fabioz for the PR (126)!
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 theraising
parameter of theqtbot.waitSignal
andqtbot.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 newassertNotEmitted
context manager which can be used to ensure the given signal is not emitted (92). Thanks @The-Compiler for the PR!
SignalBlocker
now has aargs
attribute with the arguments of the signal that triggered it, orNone
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 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 newwait
method which does a blocking wait while the event loop continues to run, similar toQTest::qWait
. Thanks @The-Compiler for the PR (closes 107)!- raise
RuntimeError
instead ofImportError
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 anextend
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 topyqt4v2
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).
pytestqt.plugin
has been split in several files (74) and tests have been moved out of thepytestqt
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 is specially problematic in
PyQt5.5
, which changed the behavior to callabort
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);
- 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;
- 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 untill all signals given are triggered (thanks @The-Compiler for idea and complete PR). - New parameter
raising
towaitSignals
andwaitSignals
: whenTrue
will raise aqtbot.SignalTimeoutError
exception when timeout is reached (defaults toFalse
). (thanks again to @The-Compiler for idea and complete PR). pytest-qt
now requirespytest
version >= 2.7.
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;
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 oldPYTEST_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 setsQString
andQVariant
APIs to2
for PyQt, making it compatible for those still using version1
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. (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).
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)
Added
stop
as 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.
Python 3 support.
Minor documentation fixes.
Small bug fix release.
First working version.