Skip to content

Commit 598c1c2

Browse files
authored
Merge pull request #152 from montefra/fix_pyqt4v2
Update documentation on ``pyqt4v2``
2 parents e5f4467 + 23f6bc3 commit 598c1c2

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pytest-qt
2424
virtual_methods
2525
modeltester
2626
app_exit
27+
note_pyqt4v2
2728
reference
2829
changelog
2930

docs/intro.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,21 @@ this order:
4040

4141
To force a particular API, set the configuration variable ``qt_api`` in your ``pytest.ini`` file to
4242
``pyqt5``, ``pyside``, ``pyqt4`` or ``pyqt4v2``. ``pyqt4v2`` sets the ``PyQt4``
43-
API to `version 2 <version2>`_.
43+
API to `version 2`_.
4444

4545
.. code-block:: ini
4646
4747
[pytest]
4848
qt_api=pyqt5
4949
50+
Alternatively, you can set the ``PYTEST_QT_API`` environment variable to the
51+
same values described above (the environment variable wins over the
52+
configuration if both are set).
5053

51-
Alternatively, you can set the ``PYTEST_QT_API`` environment
52-
variable to the same values described above (the environment variable wins over the configuration
53-
if both are set).
54+
From ``pytest-qt`` version 2 the behaviour of ``pyqt4v2`` has changed, as
55+
explained in :doc:`note_pyqt4v2`.
5456

55-
.. _version2: http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
57+
.. _version 2: http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
5658

5759
Installation
5860
------------
@@ -77,9 +79,13 @@ activate a new fresh environment and execute::
7779

7880
git clone https://github.com/pytest-dev/pytest-qt.git
7981
cd pytest-qt
80-
python setup.py develop
82+
pip install -e . # or python setup.py develop
8183
pip install pyside # or pyqt4/pyqt5
8284

85+
If you also intend to build the documentation locally, you can make sure to have
86+
all the needed dependences executing::
87+
88+
pip install -e .[doc]
8389

8490
.. _virtualenv: https://virtualenv.readthedocs.io/
8591

docs/note_pyqt4v2.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
A note about ``pyqt4v2``
2+
------------------------
3+
4+
Starting with ``pytest-qt`` version 2.0, ``PyQt`` or ``PySide`` are lazily
5+
loaded when first needed instead of at pytest startup. This usually means
6+
``pytest-qt`` will import ``PyQt`` or ``PySide`` when the tests actually start
7+
running, well after ``conftest.py`` files and other plugins have been imported.
8+
This can lead to some unexpected behaviour if ``pyqt4v2`` is set.
9+
10+
If the ``conftest.py`` files, either directly or indirectly, set the API version
11+
to 2 and import ``PyQt4``, one of the following cases can happen:
12+
13+
* if all the available types are set to version 2, then using ``pyqt4`` or
14+
``pyqt4v2`` is equivalent
15+
* if only some of the types set to version 2, using ``pyqt4v2`` will make ``pytest``
16+
to fail with an error similar to::
17+
18+
INTERNALERROR> sip.setapi("QDate", 2)
19+
INTERNALERROR> ValueError: API 'QDate' has already been set to version 1
20+
21+
If this is the case, use ``pyqt4``.
22+
23+
If the API is set in the test functions or in the code imported by them, then
24+
the new behaviour is indistinguishable from the old one and ``pyqt4v2`` must be
25+
used to avoid errors if version 2 is used.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def run_tests(self):
3737
'pytest11': ['pytest-qt = pytestqt.plugin'],
3838
},
3939
install_requires=['pytest>=2.7.0'],
40+
extras_require={'doc': ['sphinx', 'sphinx_rtd_theme']},
4041

4142
# metadata for upload to PyPI
4243
author="Bruno Oliveira",

0 commit comments

Comments
 (0)