Skip to content

Commit be76a0e

Browse files
committed
Fix aiohttp test client cleanup
1 parent 5ff16ec commit be76a0e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import os
6+
import asyncio
67
import logging
78
from typing import TYPE_CHECKING, Iterator, AsyncIterator
89

@@ -94,6 +95,7 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncRunloop]:
9495
# defaults
9596
strict = True
9697
http_client: None | httpx.AsyncClient = None
98+
needs_aiohttp_cleanup = False
9799

98100
if isinstance(param, bool):
99101
strict = param
@@ -104,10 +106,14 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncRunloop]:
104106
http_client_type = param.get("http_client", "httpx")
105107
if http_client_type == "aiohttp":
106108
http_client = DefaultAioHttpClient()
109+
needs_aiohttp_cleanup = True
107110
else:
108111
raise TypeError(f"Unexpected fixture parameter type {type(param)}, expected bool or dict")
109112

110113
async with AsyncRunloop(
111114
base_url=base_url, bearer_token=bearer_token, _strict_response_validation=strict, http_client=http_client
112115
) as client:
113116
yield client
117+
118+
if needs_aiohttp_cleanup:
119+
await asyncio.sleep(0)

0 commit comments

Comments
 (0)