How to use mock in django?

I tried installing the mock library for django from http://www.voidspace.org.uk/python/mock/

But when I type

pip install -U mock 

while in virtualenv and then try

 import mock 

from the django project shell I get:

 ImportError: No module named mock 

What can I do?

+4
source share
2 answers

Check if the module is in transit. To do this, in the Python shell:

 >>> import sys >>> print sys.path 

If it was installed correctly, you should see the mock directory in one of the printed directories.

If you did not find the mock directory, I assume pip does not install the module in the virtualenv package directory.

+3
source

OK, that was my mistake.

I ran the shell and tests:

 ./manage.py 

instead

 python manage 

therefore, my virtualenv directory was not included in sys.path, and the package layout was incompatible. Thanks for the help.

+1
source

Source: https://habr.com/ru/post/1381047/


All Articles