我對谷歌應用引擎和python相當陌生,請耐心等待。 我試圖運行在GAE上的第一次蟒蛇單元測試,而在之後Webapp2如何在谷歌應用引擎中運行python單元測試
導但是,當我運行測試我不斷收到以下錯誤:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import webapp2
ImportError: No module named webapp2
這是我的測試.py文件:
import unittest
import webapp2
# from the app main.py
import main
class TestHandlers(unittest.TestCase):
def test_hello(self):
# Build a request object passing the URI path to be tested.
# You can also pass headers, query arguments etc.
request = webapp2.Request.blank('/')
# Get a response for that request.
response = request.get_response(main.app)
# Let's check if the response is correct.
self.assertEqual(response.status_int, 200)
self.assertEqual(response.body, 'Hello, world!')
if __name__ == '__main__':
unittest.main()
這是我的main.py文件:
import webapp2
class HelloHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, world!')
app = webapp2.WSGIApplication([('/', HelloHandler)])
def main():
app.run()
if __name__ == '__main__':
main()
這是我的app.yaml文件:
application: test-app
version: 1
runtime: python27
api_version: 1
threadsafe: true
- url: /.*
script: main.app
libraries:
- name: jinja2
version: latest
builtins:
- remote_api: on
我現在的文件夾結構是:
Test-app
app.yaml
main.py
test.py
index.yaml
並運行測試我做:
$ cd test-app
$ python test.py
任何人都可以指出我的寫作方向,爲什麼我會收到上面的錯誤信息,爲什麼我不能運行這個簡單的進行測試。
我試圖發佈儘可能多的信息,希望就足夠了,有人給我一隻小手。
謝謝。
雖然一般來說這對於很多第三方庫是正確的,但它對許多django版本,webapp和webapp2等是不正確的。請參閱運行時提供的第三方庫文檔。 https://developers.google.com/appengine/docs/python/tools/libraries27 –