Skip to content

Commit d9491ce

Browse files
committed
Supporting qWaitForWindowShown in Qt5 and updated documentation
1 parent 51ef5a3 commit d9491ce

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ Requirements
5656

5757
Python 2.6 or later, including Python 3+.
5858

59-
Works with either PySide_ or
60-
PyQt_ picking whichever is available on the system, giving
61-
preference to ``PySide`` if both are installed (to force it to use ``PyQt``, set
62-
the environment variable ``PYTEST_QT_FORCE_PYQT=true``).
59+
Works with either PySide_, PyQt_ (``PyQt4`` and ``PyQt5``) picking whichever
60+
is available on the system, giving preference to the first one installed in
61+
this order:
62+
63+
- ``PySide``
64+
- ``PyQt4``
65+
- ``PyQt5``
66+
67+
To force a particular version of PyQt_, set the environment variable
68+
``PYTEST_QT_FORCE_PYQT=4`` or ``PYTEST_QT_FORCE_PYQT=5``.
6369

6470
Documentation
6571
=============

docs/index.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ Python 2.6 or later, including Python 3+.
2626

2727
Tested with pytest version 2.5.2.
2828

29-
Works with either `PySide` or
30-
`PyQt`, picking one that is available giving
31-
preference to `PySide` if both are installed (to force it to use `PyQt`, set
32-
the environment variable `PYTEST_QT_FORCE_PYQT=true`).
29+
Works with either ``PySide``, ``PyQt4`` or ``PyQt5``, picking whichever
30+
is available on the system giving preference to the first one installed in
31+
this order:
32+
33+
- ``PySide``
34+
- ``PyQt4``
35+
- ``PyQt5``
36+
37+
To force a particular version of ``PyQt``, set the environment variable
38+
``PYTEST_QT_FORCE_PYQT=4`` or ``PYTEST_QT_FORCE_PYQT=5``.
3339

3440
Installation
3541
============

pytestqt/plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,16 @@ def waitForWindowShown(self, widget):
199199
200200
:param QWidget widget:
201201
Widget to wait on.
202+
203+
.. note:: In Qt5, the actual method called is qWaitForWindowExposed,
204+
but this name is kept for backward compatibility
202205
"""
203-
QtTest.QTest.qWaitForWindowShown(widget)
206+
if hasattr(QtTest.QTest, 'qWaitForWindowShown'):
207+
# PyQt4 and PySide
208+
QtTest.QTest.qWaitForWindowShown(widget)
209+
else:
210+
# PyQt5
211+
QtTest.QTest.qWaitForWindowExposed(widget)
204212

205213
wait_for_window_shown = waitForWindowShown # pep-8 alias
206214

pytestqt/qt_compat.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@
2626
msg = 'pytest-qt requires either PyQt4 or PySide to be installed'
2727
raise ImportError(msg)
2828

29-
PYQT_VER = os.environ.get('PYTEST_QT_FORCE_PYQT', '4')
30-
# backward compatibility
31-
if PYQT_VER == 'true':
32-
PYQT_VER = '4'
33-
if PYQT_VER not in ('4', '5'):
34-
raise RuntimeError('Unsupported PyQt version: %s' % PYQT_VER)
29+
if 'PYTEST_QT_FORCE_PYQT' in os.environ:
30+
PYQT_VER = os.environ.get('PYTEST_QT_FORCE_PYQT', '4')
31+
# backward compatibility
32+
if PYQT_VER == 'true':
33+
PYQT_VER = '4'
34+
if PYQT_VER not in ('4', '5'):
35+
msg = 'Unsupported PyQt version in $PYTEST_QT_FORCE_PYQT: %s'
36+
raise RuntimeError(msg % PYQT_VER)
37+
else:
38+
# give preference for PyQt4 for backward compatibility
39+
try:
40+
import PyQt4
41+
PYQT_VER = '4'
42+
except ImportError:
43+
import PyQt5
44+
PYQT_VER = '5'
3545

3646
USING_PYSIDE = False
3747

0 commit comments

Comments
 (0)