0

I have created my project on Linux mint 19 with python 3.6 installed. I used pytest in conjunction with pytest-qt to test my app which is a PyQt5 program.

Then, I've updated to Linux mint 20. However python 3.8 is installed there instead of 3.6. I don't know whether it's related or not but now I can't run my test suite anymore, when I type pytest in terminal it gives me the following output:

Traceback (most recent call last):
  File "/home/kotlin/.local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config = outcome.get_result()  # type: Config
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1280, in parse
    self._preparse(args, addopts=addopts)
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1172, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/kotlin/.local/lib/python3.8/site-packages/pluggy/manager.py", line 299, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line 171, in exec_module
    exec(co, module.__dict__)
  File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/plugin.py", line 7, in <module>
    from pytestqt.qt_compat import QtCore, QtGui, QtTest
  File "/home/kotlin/.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line 171, in exec_module
    exec(co, module.__dict__)
  File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/qt_compat.py", line 31, in <module>
    import PyQt4.QtCore as _QtCore
ModuleNotFoundError: No module named 'PyQt4'

At the end it says ModuleNotFoundError: No module named 'PyQt4' but I don't even use PyQt4, I use PyQt5 instead.

I have pytest and pytest-qt both installed. The program itself works properly.

Thanks.

acmpo6ou
  • 840
  • 1
  • 12
  • 21
  • Well, the problem is not this. I made a fresh install i.e. I've wiped my disk and installed Linux mint 20. – acmpo6ou Oct 13 '20 at 15:38
  • Hm ok - I just checked and the wheel actually shall be compatible with both versions, so yes, this is not the problem. – MrBean Bremen Oct 13 '20 at 15:39
  • 1
    Do you have the current version of pytest-qt (5.15.1)? There shall be no reference to Qt4, I just checked with the code. What does `pip list` say? – MrBean Bremen Oct 13 '20 at 15:43
  • I installed `pytest-qt` using this command: `pip3 install pytest-qt`, here is the version `1.2.0`. You were right! I installed a newer version like this `pip3 -U install pytest-qt`. I don't know why it has installed the old version for me. Anyway thanks, you can post an answer now. – acmpo6ou Oct 13 '20 at 15:50
  • 1
    I only gave you the hints, you found it out - you can write an answer yourself :) – MrBean Bremen Oct 13 '20 at 16:13
  • 1
    Nope, I want to give you reputation! Please write the answer, because I'm gonna fill bad about that, it's like when you didn't say thanks to someone who helped you. – acmpo6ou Oct 13 '20 at 16:15

1 Answers1

1

This part of the error message:

  File "/home/kotlin/.local/lib/python3.8/site-packages/pytestqt/qt_compat.py", line 31, in <module>
    import PyQt4.QtCore as _QtCore
ModuleNotFoundError: No module named 'PyQt4'

hints at the problem - the used qt-pytest version still references PyQt4, while the current version has these references removed some time ago -- meaning the installed python-qt version is outdated. The version can be updated using

pip3 install -U pytest-qt

as mentioned in the comments. It is still unclear why an old version was installed in the first place - one possibility is that an old version already had been installed by some other package, installing it via pip (without the update option) would not do anything in this case.

MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46