Py学习  »  tornado

pytest tornado:“simpleAsynchHttpClient”不可iterable

sungyong • 7 年前 • 2280 次点击  

尝试在pytest,tornado下为长轮询生成测试代码。

我的测试代码在下面。

混杂的事物

from tornado.httpclient import  AsyncHTTPClient


@pytest.fixture
async def tornado_server():
    print("\ntornado_server()")

@pytest.fixture
async def http_client(tornado_server):
    client = AsyncHTTPClient()
    return client


@pytest.yield_fixture(scope='session')
def event_loop(request):
    loop = asyncio.get_event_loop_policy().new_event_loop()
    yield loop
    loop.close()

TestMy.Py

from tornado.httpclient import HTTPRequest, HTTPError
def test_http_client(event_loop):
    url = 'http://httpbin.org/get'
    resp = event_loop.run_until_complete(http_client(url))
    assert b'HTTP/1.1 200 OK' in resp

我希望这个结果能成功。 但失败了。

def test_http_client(event_loop):
    url = 'http://httpbin.org/get'
    resp = event_loop.run_until_complete(http_client(url))
   assert b'HTTP/1.1 200 OK' in resp E       TypeError: argument of type 'SimpleAsyncHTTPClient' is not iterable

我做错了什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/31576
文章 [ 2 ]  |  最新文章 7 年前