2014-12-02 44 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就會自動添加到您的路徑中。