簡體   English   中英

將pytest與Google AppEngine一起使用

[英]Using pytest with Google AppEngine

我的GAE應用程序在本地主機上(使用dev_appserver.py app )以及在部署時( appcfg.py name update app/ )正確運行

但是,當我對測試代碼(在我應用的目錄中)運行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/

我已經將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

如何獲取py.test以找到google.appengine.ext?

就像是

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

在您的測試中可能會起作用,但最好使用帶有鼻通氣擴展功能的鼻子測試。

您看到錯誤,因為Google App Engine SDK不在您的Python路徑中。

您可以在測試腳本或程序包的開頭手動干預sys.path ,使用鼻子擴展,或者使用(無恥的插件-我寫過) testable_appengine來通過Google的SDK和其他工具自動設置virtualenv好東西(例如鼻子,沒有鼻子年齡插件)。 它可以無縫運行,因為一旦激活virtualenv,SDK就會自動添加到您的路徑中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM