How to run python test tests in Google App Engine

I am new to Google engine and python, so please bear with me. I am trying to run the python unit test on gae for the first time, following the tutorial in Webapp2

But when I run the test, I keep getting the following error:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import webapp2
ImportError: No module named webapp2

This is my test.py file:

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 check if the response is correct.
       self.assertEqual(response.status_int, 200)
       self.assertEqual(response.body, 'Hello, world!')

if __name__ == '__main__':
    unittest.main()

This is my main.py file:

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()

This is my app.yaml file:

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

My current folder structure:

Test-app
         app.yaml
         main.py
         test.py
         index.yaml

And to run the test that I am running:

$ cd test-app
$ python test.py

Can someone point me in the direction of recording why I am getting the error message above and why I cannot run this simple test.

I tried to publish as much information as I could, I hope it will be enough for someone to give me a small hand.

Thanks.

+4
3

webapp2 , app.yaml

https://developers.google.com/appengine/docs/python/tools/libraries27

libraries:
- name: webapp2
  version: "latest" 

app.yaml, webapp2 .

, .

+2

, , .

, webapp2 Google (google_appengine/lib/webapp2-2.5.2). , , , google_appengine/lib $PYTHONPATH, "import webapp2" , .

, virtualenv, google_appengine/lib () $PYTHONPATH virtualenv, :

# add2virtualenv ---> adds/this/directory/to/the/PYTHONPATH
$ add2virtualenv google_appengine/lib/webapp2-2.5.2 

# check which directories have been added to the virtualenv
$ add2virtualenv
Usage: add2virtualenv dir [dir ...]

Existing paths:
google_appengine/lib/webapp2-2.5.2 

, .

+1

Google App Engine -: Django, web.py, webapp2 , . ( webbapp2) .

webapp2 .

, :

Test-app
     app.yaml
     main.py
     test.py
     index.yaml
     webapp2/

!

, .

-1

All Articles