Skip to content

Commit cc20641

Browse files
committed
change tests from respx mocks to pytest-httpserver
1 parent 8d75b7d commit cc20641

File tree

10 files changed

+732
-218
lines changed

10 files changed

+732
-218
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dev = [
5252
"pytest-timeout>=2.4.0",
5353
"pytest-xdist~=3.8.0",
5454
"pytest~=8.4.0",
55+
"pytest-httpserver>=1.1.3",
5556
"redbaron~=0.9.0",
5657
"respx~=0.22.0",
5758
"ruff~=0.12.0",

tests/integration/__init__.py

Whitespace-only changes.

tests/unit/__init__.py

Whitespace-only changes.

tests/unit/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from collections.abc import Iterable, Iterator
2+
from logging import getLogger
3+
4+
import pytest
5+
from pytest_httpserver import HTTPServer
6+
7+
8+
@pytest.fixture(scope='session')
9+
def make_httpserver() -> Iterable[HTTPServer]:
10+
werkzeug_logger = getLogger('werkzeug')
11+
werkzeug_logger.disabled = True
12+
13+
server = HTTPServer(threaded=True)
14+
server.start()
15+
yield server
16+
server.clear() # type: ignore[no-untyped-call]
17+
if server.is_running():
18+
server.stop() # type: ignore[no-untyped-call]
19+
20+
21+
@pytest.fixture(scope='session')
22+
def httpserver(make_httpserver: HTTPServer) -> HTTPServer:
23+
return make_httpserver
24+
25+
26+
@pytest.fixture
27+
def patch_basic_url(httpserver: HTTPServer, monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
28+
server_url = httpserver.url_for('/').removesuffix('/')
29+
monkeypatch.setattr('apify_client.client.DEFAULT_API_URL', server_url)
30+
yield
31+
monkeypatch.undo()

0 commit comments

Comments
 (0)