Import memcache from google.appengine.api without using dev_appserver.py

According to the Google AppEngine documentation, you should import memcache as follows:

from google.appengine.api import memcache 

I use virtualenv and I create some scripts to test the library that I created for AppEngine. I am not trying to test a website, I am trying to test a specific library using memcache. Obviously, without using dev_appserver.py I get ImportError: No module named google.appengine.api .

I looked at the source dev_appserver.py , but first I would like to know if there is a simpler solution that would not require rewriting PATH, as Google does.

Thanks!

+4
source share
2 answers

There is no easy solution, at least you have to tune Python paths. That all the dev_appserver wrappers you are associated with is there. For code / library testing, I usually write a simple shell that does basically the same thing that dev_appserver does.

In some cases, you really need to go further and initialize the stubs. If you execute the dev_appserver code, you can see how this is done.

+2
source

For testing purposes, we always create a local AppEngine library check as follows:

 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 
+2
source

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


All Articles