异步 HTTP 测试用例龙卷风 599
AsyncHTTPTestCase Tornado 599
我正在尝试使用 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
环境
- 龙卷风=5.0.2
- Python=3.6.5
错误
tornado.httpclient.HTTPError: HTTP 599: Stream closed
对于我做错了什么的任何见解或帮助将不胜感激。
错误在 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"
注意get_app
函数中的return
。
我还编辑了断言以通过测试。
我正在尝试使用 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
环境
- 龙卷风=5.0.2
- Python=3.6.5
错误
tornado.httpclient.HTTPError: HTTP 599: Stream closed
对于我做错了什么的任何见解或帮助将不胜感激。
错误在 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"
注意get_app
函数中的return
。
我还编辑了断言以通过测试。