AsyncHTTPTestCase龙卷风599

时间:2018-10-03 22:48:55

标签: tornado

我正在尝试使用AsyncHTTPTestCase示例,但我一直收到599错误。

我在下面尝试了相同的示例,但是没有协程装饰器,只是使用了self.fetch,但是我仍然遇到相同的错误。

app.py

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

test_app.py

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"

测试命令

pytest test_app.py

环境

  • Tornado = 5.0.2
  • Python = 3.6.5

错误

tornado.httpclient.HTTPError: HTTP 599: Stream closed

任何对我做错事的见识或帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

错误在test_app.py文件中。

test_app.py

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"

请注意return函数中的get_app

我还编辑了断言以使测试通过。