Skip to content

Instantly share code, notes, and snippets.

@ajdavis
Created November 11, 2014 17:50
Show Gist options
  • Save ajdavis/69b12c7ee77d6ae010d0 to your computer and use it in GitHub Desktop.
Save ajdavis/69b12c7ee77d6ae010d0 to your computer and use it in GitHub Desktop.
from tornado.testing import AsyncHTTPTestCase, gen_test
from tornado.web import Application
from tornado.web import RequestHandler
from tornado.gen import coroutine, Return
class HelloHandler(RequestHandler):
@coroutine
def get(self):
msg = yield self.task()
self.write(msg)
@coroutine
def task(self):
raise Return('Hello world!')
class HelloHandlerTest(AsyncHTTPTestCase):
def get_app(self):
return Application(
[(r'/', HelloHandler)],
)
@gen_test
def test_one(self):
res = yield self.http_client.fetch(self.get_url('/'))
assert res.error is None, 'error: %s' % str(res.error)
import unittest
unittest.main()
@ajdavis
Copy link
Author

ajdavis commented Nov 11, 2014

Output:

$ python async_test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.010s

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment