File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,10 +56,16 @@ Requirements
5656
5757Python 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
6470Documentation
6571=============
Original file line number Diff line number Diff line change @@ -26,10 +26,16 @@ Python 2.6 or later, including Python 3+.
2626
2727Tested 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
3440Installation
3541============
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments