tornado: construct AsyncHTTPClient each time so that it uses the right ioloop

This is a better fix for #129.
This commit is contained in:
lilydjwg 2020-07-02 15:07:19 +08:00
parent 2fc1ec3355
commit cbd7e13867
2 changed files with 2 additions and 5 deletions

View File

@ -17,7 +17,6 @@ from .httpclient import DEFAULT_USER_AGENT
__all__ = ['session', 'HTTPError', 'NetworkErrors']
client = AsyncHTTPClient()
HTTP2_AVAILABLE = None if pycurl else False
def try_use_http2(curl):
@ -66,7 +65,7 @@ class ResponseManager:
self.req = req
async def __aenter__(self):
return await client.fetch(self.req)
return await AsyncHTTPClient().fetch(self.req)
async def __aexit__(self, exc_type, exc, tb):
pass

View File

@ -54,12 +54,10 @@ async def get_version():
return __call__
@pytest.fixture(scope="session")
@pytest.fixture(scope="module")
def event_loop(request):
"""Override pytest-asyncio's event_loop fixture,
Don't create an instance of the default event loop for each test case.
The scope is session because the Tornado AsyncHTTPClient singleton remains.
"""
loop = asyncio.get_event_loop()
yield loop