Skip to content

Runtime error when running pytest with PyQt5 application #1701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mandeep opened this issue Jul 5, 2016 · 6 comments
Closed

Runtime error when running pytest with PyQt5 application #1701

mandeep opened this issue Jul 5, 2016 · 6 comments

Comments

@mandeep
Copy link
Contributor

mandeep commented Jul 5, 2016

Having a problem running pytest with a PyQt5 application. When running this command: py.test tests.py, I receive an error saying:

tests.py:3: in <module>
    import application
application.py:3: in <module>
    from PyQt5.QtGui import QIcon
E   RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class

I'm not sure if this is an error with pytest or pytest-qt. The code in tests.py is as follows:

import os
import sys
import application
import pytest
from PyQt5.QtGui import QIcon
from PyQt5.QtPrintSupport import QPrintDialog
from PyQt5.QtWidgets import (QMainWindow, QApplication, QTextEdit, QAction,
                             QFileDialog, QFontDialog, QMessageBox, QInputDialog)


`
    class Test:

        def setup_method(self):
            app = QApplication(sys.argv)
            wind = application.TextEditor()
            wind.show()
            sys.exit(app.exec_())

Here is a conda list of the conda env. I do not have PyQt4 installed nor am I importing it anywhere:

# packages in environment at /home/mandeep/anaconda3:
#
_license                  1.1                      py35_1  
abstract-rendering        0.5.1               np110py35_0  
alabaster                 0.7.7                    py35_0  
anaconda                  2.5.0               np110py35_0  
anaconda-client           1.4.0                    py35_0  
argcomplete               1.0.0                    py35_1  
argparse                  1.4.0                     <pip>
astropy                   1.1.2               np110py35_0  
attrs                     15.2.0                    <pip>
autoenv                   1.0.0                     <pip>
babel                     2.3.3                    py35_0  
backports                 1.0                      py35_0  
beautifulsoup4            4.4.1                    py35_0  
bitarray                  0.8.1                    py35_0  
blaze-core                0.9.0                    py35_0  
bokeh                     0.11.1                   py35_0  
boto                      2.40.0                   py35_0  
bottleneck                1.0.0               np110py35_0  
cffi                      1.6.0                    py35_0  
clyent                    1.2.2                    py35_0  
colorama                  0.3.7                    py35_0  
conda                     4.1.6                    py35_0  
conda-build               1.20.3                   py35_0  
conda-env                 2.5.1                    py35_0  
configobj                 5.0.6                    py35_0  
coverage                  4.0.3                     <pip>
coverage                  4.0.3                    py35_0  
cryptography              1.3.1                    py35_0  
cssselect                 0.9.1                     <pip>
curl                      7.45.0                        0  
cycler                    0.10.0                   py35_0  
cython                    0.24                     py35_0  
cytoolz                   0.7.5                    py35_0  
datashape                 0.5.2                    py35_0  
decorator                 4.0.9                    py35_0  
Django                    1.9.2                     <pip>
django                    1.9.5                    py35_0  
docutils                  0.12                     py35_0  
dynd-python               0.7.2                    py35_0  
entrypoints               0.2                      py35_1  
enum34                    1.1.2                     <pip>
et_xmlfile                1.0.1                    py35_0  
fastcache                 1.0.2                    py35_0  
flake8                    2.5.1                    py35_0  
flask                     0.10.1                   py35_1  
fontconfig                2.11.1                        5  
freetype                  2.5.5                         0  
futures                   3.0.3                    py35_0  
get_terminal_size         1.0.0                    py35_0  
greenlet                  0.4.9                    py35_0  
h5py                      2.6.0               np110py35_1  
hdf5                      1.8.16                        0  
idna                      2.1                      py35_0  
imagesize                 0.7.1                    py35_0  
ipykernel                 4.3.1                    py35_0  
ipython                   4.2.0                    py35_0  
ipython-notebook          4.0.4                    py35_0  
ipython-qtconsole         4.0.1                    py35_0  
ipython_genutils          0.1.0                    py35_0  
ipywidgets                4.1.1                    py35_0  
itsdangerous              0.24                     py35_0  
jbig                      2.1                           0  
jdcal                     1.2                      py35_0  
jedi                      0.9.0                    py35_0  
jellyfish                 0.5.2                     <pip>
jinja2                    2.8                      py35_0  
jpeg                      8d                            0  
jsonschema                2.5.1                    py35_0  
jupyter                   1.0.0                    py35_2  
jupyter_client            4.2.2                    py35_0  
jupyter_console           4.1.1                    py35_0  
jupyter_core              4.1.0                    py35_0  
libdynd                   0.7.2                         0  
libffi                    3.2.1                         0  
libgfortran               3.0.0                         1  
libpng                    1.6.17                        0  
libsodium                 1.0.3                         0  
libtiff                   4.0.6                         1  
libxml2                   2.9.2                         0  
libxslt                   1.1.28                        0  
llvmlite                  0.10.0                   py35_0  
lxml                      3.6.0                    py35_0  
markupsafe                0.23                     py35_0  
matplotlib                1.5.1               np110py35_0  
mccabe                    0.3.1                    py35_0  
mistune                   0.7.2                    py35_0  
mkl                       11.3.3                        0  
mkl-service               1.1.2                    py35_1  
mpmath                    0.19                     py35_1  
multipledispatch          0.4.8                    py35_0  
munkres                   1.0.7                     <pip>
musicbrainzngs            0.5                       <pip>
mutagen                   1.31                      <pip>
nbconvert                 4.2.0                    py35_0  
nbformat                  4.0.1                    py35_0  
networkx                  1.11                     py35_0  
nltk                      3.2.1                    py35_0  
nose                      1.3.7                    py35_0  
notebook                  4.2.0                    py35_0  
numba                     0.25.0              np110py35_0  
numexpr                   2.5.2               np110py35_1  
numpy                     1.10.4                   py35_2  
odo                       0.5.0                    py35_0  
openblas                  0.2.14                        0  
openpyxl                  2.3.2                    py35_0  
openssl                   1.0.2h                        0  
pandas                    0.18.1              np110py35_0  
patchelf                  0.8                           0  
path.py                   8.2.1                    py35_0  
patsy                     0.4.1                    py35_0  
pbr                       1.8.1                     <pip>
pep8                      1.7.0                    py35_0  
pexpect                   4.0.1                    py35_0  
pickleshare               0.5                      py35_0  
pillow                    3.2.0                    py35_0  
pip                       8.1.1                    py35_1  
pip                       8.1.2                     <pip>
ply                       3.8                      py35_0  
psutil                    4.2.0                    py35_0  
ptyprocess                0.5                      py35_0  
py                        1.4.31                   py35_0  
pyasn1                    0.1.9                    py35_0  
pyasn1-modules            0.0.8                     <pip>
pycosat                   0.6.1                    py35_0  
pycparser                 2.14                     py35_0  
pycrypto                  2.6.1                    py35_0  
pycurl                    7.19.5.3                 py35_0  
pyflakes                  1.0.0                     <pip>
pyflakes                  1.1.0                    py35_0  
pygments                  2.1.3                    py35_0  
pyopenssl                 0.15.1                   py35_2  
pyparsing                 2.1.1                    py35_0  
pyperclip                 1.5.26                    <pip>
pyqt                      4.11.4                   py35_1  
PyQt5                     5.6                       <pip>
pytables                  3.2.2               np110py35_3  
pytest                    2.9.1                     <pip>
pytest                    2.9.2                    py35_0  
pytest-qt                 1.11.0                    <pip>
python                    3.5.1                         5  
python-dateutil           2.5.3                    py35_0  
pytz                      2016.4                   py35_0  
pyyaml                    3.11                     py35_1  
pyzmq                     15.2.0                   py35_0  
qt                        4.8.7                         1  
qtconsole                 4.2.1                    py35_0  
queuelib                  1.4.2                     <pip>
readline                  6.2                           2  
redis                     2.6.9                         0  
redis-py                  2.10.3                   py35_0  
requests                  2.10.0                   py35_0  
rope                      0.9.4                    py35_1  
ruamel_yaml               0.11.7                   py35_0  
scikit-image              0.12.3              np110py35_0  
scikit-learn              0.17.1              np110py35_1  
scipy                     0.17.1              np110py35_0  
Scrapy                    1.0.5                     <pip>
selenium                  2.53.2                    <pip>
service-identity          16.0.0                    <pip>
setuptools                20.7.0                   py35_0  
simplegeneric             0.8.1                    py35_0  
sip                       4.16.9                   py35_0  
sip                       4.18                      <pip>
six                       1.10.0                   py35_0  
snowballstemmer           1.2.1                    py35_0  
sockjs-tornado            1.0.1                    py35_0  
sphinx                    1.4.1                    py35_0  
sphinx_rtd_theme          0.1.9                    py35_0  
spyder                    2.3.8                    py35_1  
spyder-app                2.3.8                    py35_0  
sqlalchemy                1.0.13                   py35_0  
sqlite                    3.13.0                        0  
statsmodels               0.6.1               np110py35_0  
stevedore                 1.10.0                    <pip>
sympy                     1.0                      py35_0  
system                    5.8                           2  
terminado                 0.5                      py35_1  
theano                    0.7.0               np110py35_0  
tk                        8.5.18                        0  
toolz                     0.7.4                    py35_0  
tornado                   4.3                      py35_0  
traitlets                 4.2.1                    py35_0  
Twisted                   15.5.0                    <pip>
ujson                     1.35                     py35_0  
unicodecsv                0.14.1                   py35_0  
Unidecode                 0.4.19                    <pip>
util-linux                2.21                          0  
virtualenv                14.0.3                    <pip>
virtualenv-clone          0.2.6                     <pip>
virtualenvwrapper         4.7.1                     <pip>
w3lib                     1.13.0                    <pip>
werkzeug                  0.11.9                   py35_0  
wheel                     0.29.0                   py35_0  
xlrd                      0.9.4                    py35_0  
xlsxwriter                0.8.7                    py35_0  
xlwt                      1.0.0                    py35_0  
xz                        5.2.2                         0  
yaml                      0.1.6                         0  
zeromq                    4.1.3                         0  
zlib                      1.2.8                         0  
zope.interface            4.1.3                     <pip>

(edited by @The-Compiler to add code block formatting around outputs/code)

@The-Compiler
Copy link
Member

This should probably have gone to the pytest-qt issue tracker but I'll answer here anyways 😉

According to that output, you do have PyQt4 installed:

pyqt                      4.11.4                   py35_1

Do you set PYTEST_QT_API=pyqt5 in your environment to select that? If not, you should. Otherwise, pytest-qt prefers PyQt4 and imports that, which I believe leads to the error you're seeing - @nicoddemus probably knows more 😉

We'll soon release pytest-qt 2.0 which will prefer PyQt5 by default and also lets you configure the Qt API in your pytest.ini.

@mandeep
Copy link
Contributor Author

mandeep commented Jul 5, 2016

Hi The-Compiler, thanks for answering my question here. I tried setting my environment variable and removing qt4, unfortunately I still receive qt4 related errors. There's no rush to write these tests, so I will happily wait for pytest-qt 2.0. Thanks again, Mandeep.

@The-Compiler
Copy link
Member

Weird - do you still get the exact same error?

@RonnyPfannschmidt
Copy link
Member

btw, can we close this on the pytest tracker, its a pytest-qt issue and the next pytest-qt will fix it

@The-Compiler
Copy link
Member

I'm closing it - I don't see any issue so far though, pytest-qt works fine with PyQt4 or PyQt5 (with both installed) here when PYTEST_QT_API is set correctly.

@mandeep
Copy link
Contributor Author

mandeep commented Jul 5, 2016

Turns out it was an issue with the environment. Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants