简体   繁体   中英

How to use mock in django?

I tried to install a mock library for django from http://www.voidspace.org.uk/python/mock/

But when i type in

pip install -U mock

while in virtualenv, and then try to

import mock

from django project's shell i get:

ImportError: No module named mock

What can I do?

Check to see if the module is in the path. 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 directories printed out.

If you do not find the mock directory, I'm assuming that pip is not installing the module in the virtualenv packages directory.

OK, it was my fault.

I ran shell and tests by:

./manage.py

instead of

python manage

so my virtualenv directory wasn't included in sys.path, and mock package was unavaible. Thanks for help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM