File tree Expand file tree Collapse file tree 4 files changed +45
-15
lines changed Expand file tree Collapse file tree 4 files changed +45
-15
lines changed Original file line number Diff line number Diff line change @@ -56,10 +56,16 @@ Requirements
56
56
57
57
Python 2.6 or later, including Python 3+.
58
58
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 ``.
63
69
64
70
Documentation
65
71
=============
Original file line number Diff line number Diff line change @@ -26,10 +26,16 @@ Python 2.6 or later, including Python 3+.
26
26
27
27
Tested with pytest version 2.5.2.
28
28
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 ``.
33
39
34
40
Installation
35
41
============
Original file line number Diff line number Diff line change @@ -199,8 +199,16 @@ def waitForWindowShown(self, widget):
199
199
200
200
:param QWidget widget:
201
201
Widget to wait on.
202
+
203
+ .. note:: In Qt5, the actual method called is qWaitForWindowExposed,
204
+ but this name is kept for backward compatibility
202
205
"""
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 )
204
212
205
213
wait_for_window_shown = waitForWindowShown # pep-8 alias
206
214
Original file line number Diff line number Diff line change 26
26
msg = 'pytest-qt requires either PyQt4 or PySide to be installed'
27
27
raise ImportError (msg )
28
28
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'
35
45
36
46
USING_PYSIDE = False
37
47
You can’t perform that action at this time.
0 commit comments