Reputation: 26049
According to the Google AppEngine documentation, one should import memcache like this:
from google.appengine.api import memcache
I'm using a virtualenv and I'm creating some scripts to test a library I created for AppEngine. I am not trying to test a website, I am trying to test a specific library that uses memcache. Evidently, without using dev_appserver.py
I get an ImportError: No module named google.appengine.api
.
I had a look at the source of dev_appserver.py
but first I'd like to know if there is a simpler solution that would not require rewriting PATH as Google does.
Thanks!
Upvotes: 4
Views: 1127
Reputation: 8292
There is no simple solution, at the minimum you'll have to setup your Python paths. That's all the dev_appserver wrapper you linked to does. For testing code / libraries I usually write a simple wrapper that does basically the same thing as dev_appserver is doing.
In some cases you'll actually need to go a step further and initialize the stubs as well. If you follow through the dev_appserver code, you'll be able to see how this is done.
Upvotes: 2
Reputation: 29983
For testing purposes we always create a local checkout of the AppEngine library like this:
GAE_VERSION=1.6.2
resttest: dependencies lib/google_appengine/google/__init__.py
sh -c "PYTHONPATH=lib/google_appengine/ python tests/resttest.py --hostname=$(TESTHOST) --credentials-user=$(CREDENTIALS_USER)"
lib/google_appengine/google/__init__.py:
curl -s -O http://googleappengine.googlecode.com/files/google_appengine_$(GAE_VERSION).zip
unzip -q google_appengine_$(GAE_VERSION).zip
rm -Rf lib/google_appengine
mv google_appengine lib/
rm google_appengine_$(GAE_VERSION).zip
dependencies:
git submodule update --init
Upvotes: 2