2014-12-02 95 views
0

我的GAE应用程序正常运行(使用dev_appserver.py app)在本地主机上,并部署时(appcfg.py name update app/与谷歌AppEngine上使用pytest

然而,当我在测试代码运行py.test(在我的应用程序的目录),我得到一个导入错误:

app/main.py:4: in <module> 
    from google.appengine.ext import db 
E ImportError: No module named google.appengine.ext 

GAE在这里安装: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ 它包含google/appengine/ext/

我加入谷歌的云-SDK来我的$ PATH,并且在/usr/local/一个符号链接到GAE:

lrwxr-xr-x 1 root  admin google_appengine -> /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine 

我怎样才能得到py.test找到google.appengine.ext?

回答

0

喜欢的东西

sys.path.insert(0, '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/') 

在测试中可以工作,但更好地利用nosetests与nose-gae扩展。

0

由于Google App Engine SDK不在您的Python路径中,您会看到该错误。

您可以手动sys.path干扰你的测试脚本或程序包的开始,用鼻GAE扩展,或者你使用类似(无耻的插件 - 我写的)testable_appengine自动设定与谷歌的SDK中的virtualenv和一些其他好东西(比如鼻子,没有鼻子插件)。它可以无缝工作,因为一旦激活了virtualenv,SDK就会自动添加到您的路径中。