mock import causes Problems on Ubuntu (missing requirement)

Issue #773 resolved
Fabian Thiel created an issue

In a fresh 21.04 Ubuntu image there is a problem with mock being a missing dependency. mock should be long integrated into Python, available as unittest.mock (see here https://pypi.org/project/mock/)
Installing mock via pip fixes the issue.

The question now is whether to put mock in requirements.txt or fix the import statements in the codebase?

Initial error message:

Traceback (most recent call last):
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox/__init__.py", line 268, in collectEnMAPBoxAlgorithms
    import enmapboxgeoalgorithms.algorithms
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxgeoalgorithms/algorithms.py", line 6, in <module>
    from enmapboxprocessing.algorithm.algorithms import algorithms
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/algorithms.py", line 3, in <module>
    from enmapboxprocessing.algorithm.classificationperformancesimplealgorithm import \
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancesimplealgorithm.py", line 6, in <module>
    from enmapboxprocessing.algorithm.classificationperformancestratifiedalgorithm import \
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/classificationperformancestratifiedalgorithm.py", line 12, in <module>
    from enmapboxprocessing.algorithm.rasterizecategorizedvectoralgorithm import RasterizeCategorizedVectorAlgorithm
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/rasterizecategorizedvectoralgorithm.py", line 12, in <module>
    from enmapboxprocessing.algorithm.rastermathalgorithm.rastermathalgorithm import RasterMathAlgorithm
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapboxprocessing/algorithm/rastermathalgorithm/rastermathalgorithm.py", line 10, in <module>
    from mock import Mock
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'mock'

Comments (8)

  1. Fabian Thiel reporter

    Maybe we need to reopen this one and check for all mock occurrences, e.g. enmapboxplugin/enmapbox/externals/qps/testing.py is also affected.
    E.g. in this case it is the statement import mock which has to be changed to import unittest.mock
    Assuming that mock == unittest.mock , but we should figure out quite fast if there are issues with that change, right?

  2. Log in to comment