I want to mock the linear algebra module in the numpy package, and I've been trying the following:
from mock import MagicMock
sys.modules["numpy.linalg"] = MagicMock()
import numpy.linalg
And I get the following error:
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 167, in <module>
from . import linalg
ImportError: cannot import name 'linalg'
It seems that while mock works with numpy.linalg
, it isn't able to mock calls of the form:
from numpy import linalg
Is there any workaround for this? Thanks a lot for your help.
Aucun commentaire:
Enregistrer un commentaire