Running the tests like that won't setup all the paths to the various 
modules provided by the appengine SDK. (including webapp2)

I would have a read of the this article on local unit testing, towards the 
bottom it tells you how to set up your environment,

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

On Friday, January 17, 2014 7:38:39 PM UTC+8, Pedro Miguel wrote:
>
>
> Hi guys,
>
> I'm fairly new to google app engine and python so please bear with me.
>
> I would like to start running some python unit tests and I've been 
> following the guide at 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's 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 is:
> test-app
>          app.yaml
>          main.py 
>          test.py
>
> And to run the test I do:
> $ cd test-app
> $ python test.py
>
> Answer that's when I get the error showed above.  Could anyone tell me 
> what am I doing wrong.
>
>
> Regards,
>
> Pedro
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to