简体   繁体   English

将pytest与Google AppEngine一起使用

[英]Using pytest with Google AppEngine

My GAE app runs correctly on the local host (using dev_appserver.py app ) and when deployed ( appcfg.py name update app/ ) 我的GAE应用程序在本地主机上(使用dev_appserver.py app )以及在部署时( appcfg.py name update app/ )正确运行

However, when I run py.test on test code (in my app's directory), I get an import error: 但是,当我对测试代码(在我应用的目录中)运行py.test时,出现导入错误:

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

GAE is installed here: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ and it contains google/appengine/ext/ GAE安装在以下位置: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/ ,其中包含google/appengine/ext/

I have added the google-cloud-sdk to my $PATH, and there is a symlink in /usr/local/ to GAE: 我已经将google-cloud-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

How can I get py.test to find google.appengine.ext? 如何获取py.test以找到google.appengine.ext?

Something like 就像是

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

in your tests may work, but better use nosetests with nose-gae extension. 在您的测试中可能会起作用,但最好使用带有鼻通气扩展功能的鼻子测试。

You see the error because the Google App Engine SDK is not in your Python path. 您看到错误,因为Google App Engine SDK不在您的Python路径中。

You can manually interfere with sys.path at the beginning of your test scripts or package, use nose-gae extension or, you use something like (shameless plug - I wrote it) testable_appengine to automate setting up a virtualenv with Google's SDK and some other nice things (like nose, without the nose-age plugins). 您可以在测试脚本或程序包的开头手动干预sys.path ,使用鼻子扩展,或者使用(无耻的插件-我写过) testable_appengine来通过Google的SDK和其他工具自动设置virtualenv好东西(例如鼻子,没有鼻子年龄插件)。 It works seamlessly because, once you activate the virtualenv, the SDK is automatically added to your path. 它可以无缝运行,因为一旦激活virtualenv,SDK就会自动添加到您的路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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