I'm trying to use the AsyncHTTPTestCase example, but I keep getting a 599 error.
I have tried the same example below, but without the coroutine decorators and just using self.fetch, but I still get the same error.
import tornado.web
import tornado.gen
class Handler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def get(self):
self.write("Hello, world")
self.finish()
def make_app():
return tornado.web.Application([
(r"/", Handler)
])
from tornado.testing import AsyncHTTPTestCase, gen_test
from app import make_app
class TestApp(AsyncHTTPTestCase):
def get_app(self):
make_app()
@gen_test(timeout=100)
def test_handler(self):
response = yield self.http_client.fetch(self.get_url("/"))
assert response == "Hello, world"
Testing command
pytest test_app.py
tornado.httpclient.HTTPError: HTTP 599: Stream closed
Any insight or help as to what I am doing wrong would be greatly appreciated.
The error is in the test_app.py file.
from tornado.testing import AsyncHTTPTestCase, gen_test
from app import make_app
class TestApp(AsyncHTTPTestCase):
def get_app(self):
return make_app()
@gen_test(timeout=100)
def test_handler(self):
response = yield self.http_client.fetch(self.get_url("/"))
assert response.body == b"Hello, world"
Note the return
in the get_app
function.
I have also edited the assert to have a test that passes.