Skip to content

Commit 25e1d75

Browse files
committed
move patched_httpx_client to conftest
1 parent 76b5b1a commit 25e1d75

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

tests/unit/actor/test_actor_create_proxy_configuration.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any
3+
from typing import TYPE_CHECKING
44
from unittest.mock import Mock
55

6-
import httpx
76
import pytest
87

98
from apify_client import ApifyClientAsync
@@ -12,8 +11,6 @@
1211
from apify import Actor
1312

1413
if 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')
4629
async def test_basic_proxy_configuration_creation(
4730
monkeypatch: pytest.MonkeyPatch,

tests/unit/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from logging import getLogger
88
from typing import TYPE_CHECKING, Any, get_type_hints
99

10+
import httpx
1011
import pytest
1112
from 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()

tests/unit/test_proxy_configuration.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import TYPE_CHECKING, Any
99
from unittest.mock import Mock
1010

11-
import httpx
1211
import pytest
1312

1413
from apify_client import ApifyClientAsync
@@ -17,8 +16,6 @@
1716
from apify._proxy_configuration import ProxyConfiguration, is_url
1817

1918
if 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-
5841
def test_basic_constructor() -> None:
5942
groups = ['GROUP1', 'GROUP2']
6043
password = 'abcd1234'

0 commit comments

Comments
 (0)