Skip to content

Commit 6a26dee

Browse files
committed
improve HttpClient isolate in tests
1 parent 01f8460 commit 6a26dee

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/unit/conftest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
import os
88
import warnings
9-
from typing import TYPE_CHECKING, cast
9+
from typing import TYPE_CHECKING, Any, cast
1010

1111
import pytest
1212
from curl_cffi import CurlHttpVersion
@@ -205,9 +205,16 @@ def redirect_server_url(redirect_http_server: TestServer) -> URL:
205205
pytest.param('curl', id='curl'),
206206
]
207207
)
208-
async def http_client(request: pytest.FixtureRequest) -> HttpClient:
208+
async def http_client(request: pytest.FixtureRequest) -> AsyncGenerator[HttpClient, None]:
209+
class_client: type[HttpClient]
209210
if request.param == 'curl':
210-
return CurlImpersonateHttpClient(http_version=CurlHttpVersion.V1_1)
211-
if request.param == 'impit':
212-
return ImpitHttpClient(http3=False)
213-
return HttpxHttpClient(http2=False)
211+
class_client = CurlImpersonateHttpClient
212+
kwargs: dict[str, Any] = {'http_version': CurlHttpVersion.V1_1}
213+
elif request.param == 'impit':
214+
class_client = ImpitHttpClient
215+
kwargs = {'http3': False}
216+
else:
217+
class_client = HttpxHttpClient
218+
kwargs = {'http2': True}
219+
async with class_client(**kwargs) as client:
220+
yield client

0 commit comments

Comments
 (0)