File tree Expand file tree Collapse file tree 3 files changed +16
-35
lines changed Expand file tree Collapse file tree 3 files changed +16
-35
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- from typing import TYPE_CHECKING , Any
3+ from typing import TYPE_CHECKING
44from unittest .mock import Mock
55
6- import httpx
76import pytest
87
98from apify_client import ApifyClientAsync
1211from apify import Actor
1312
1413if TYPE_CHECKING :
15- from collections .abc import Iterator
16-
1714 from pytest_httpserver import HTTPServer
1815 from werkzeug import Request , Response
1916
@@ -28,20 +25,6 @@ def patched_apify_client(apify_client_async_patcher: ApifyClientAsyncPatcher) ->
2825 return ApifyClientAsync ()
2926
3027
31- @pytest .fixture
32- def patched_httpx_client (monkeypatch : pytest .MonkeyPatch ) -> Iterator [None ]:
33- """Patch httpx client to avoid actual network calls."""
34-
35- class ProxylessAsyncClient (httpx .AsyncClient ):
36- def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
37- kwargs .pop ('proxy' , None )
38- super ().__init__ (* args , ** kwargs )
39-
40- monkeypatch .setattr (httpx , 'AsyncClient' , ProxylessAsyncClient )
41- yield
42- monkeypatch .undo ()
43-
44-
4528@pytest .mark .usefixtures ('patched_httpx_client' )
4629async def test_basic_proxy_configuration_creation (
4730 monkeypatch : pytest .MonkeyPatch ,
Original file line number Diff line number Diff line change 77from logging import getLogger
88from typing import TYPE_CHECKING , Any , get_type_hints
99
10+ import httpx
1011import pytest
1112from pytest_httpserver import HTTPServer
1213
@@ -209,3 +210,17 @@ def httpserver(make_httpserver: HTTPServer) -> Iterator[HTTPServer]:
209210 server = make_httpserver
210211 yield server
211212 server .clear () # type: ignore[no-untyped-call]
213+
214+
215+ @pytest .fixture
216+ def patched_httpx_client (monkeypatch : pytest .MonkeyPatch ) -> Iterator [None ]:
217+ """Patch httpx client to drop proxy settings."""
218+
219+ class ProxylessAsyncClient (httpx .AsyncClient ):
220+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
221+ kwargs .pop ('proxy' , None )
222+ super ().__init__ (* args , ** kwargs )
223+
224+ monkeypatch .setattr (httpx , 'AsyncClient' , ProxylessAsyncClient )
225+ yield
226+ monkeypatch .undo ()
Original file line number Diff line number Diff line change 88from typing import TYPE_CHECKING , Any
99from unittest .mock import Mock
1010
11- import httpx
1211import pytest
1312
1413from apify_client import ApifyClientAsync
1716from apify ._proxy_configuration import ProxyConfiguration , is_url
1817
1918if TYPE_CHECKING :
20- from collections .abc import Iterator
21-
2219 from pytest_httpserver import HTTPServer
2320 from werkzeug import Request , Response
2421
@@ -41,20 +38,6 @@ def patched_apify_client(apify_client_async_patcher: ApifyClientAsyncPatcher) ->
4138 return ApifyClientAsync ()
4239
4340
44- @pytest .fixture
45- def patched_httpx_client (monkeypatch : pytest .MonkeyPatch ) -> Iterator [None ]:
46- """Patch httpx client to avoid actual network calls."""
47-
48- class ProxylessAsyncClient (httpx .AsyncClient ):
49- def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
50- kwargs .pop ('proxy' , None )
51- super ().__init__ (* args , ** kwargs )
52-
53- monkeypatch .setattr (httpx , 'AsyncClient' , ProxylessAsyncClient )
54- yield
55- monkeypatch .undo ()
56-
57-
5841def test_basic_constructor () -> None :
5942 groups = ['GROUP1' , 'GROUP2' ]
6043 password = 'abcd1234'
You can’t perform that action at this time.
0 commit comments