Skip to content

Commit 709fe3f

Browse files
committed
feat NEXUS-817: added freezgun to control time-dependent operations
1 parent c3cf0a4 commit 709fe3f

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

_test_contract/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from datetime import timedelta
2+
3+
import pytest
4+
5+
from unstructured_client import UnstructuredClient
6+
7+
FAKE_API_KEY = "91pmLBeETAbXCpNylRsLq11FdiZPTk"
8+
9+
@pytest.fixture(scope="module")
10+
def client(platform_api_url) -> UnstructuredClient:
11+
_client = UnstructuredClient(
12+
api_key_auth=FAKE_API_KEY,
13+
server_url=platform_api_url,
14+
)
15+
yield _client
16+
17+
@pytest.fixture(autouse=True)
18+
def mock_sleep(mocker, freezer):
19+
sleep_mock = mocker.patch("time.sleep")
20+
sleep_mock.side_effect = lambda seconds: freezer.tick(timedelta(seconds=seconds))
21+
yield sleep_mock
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
import os
2-
31
import pytest
42

5-
from unstructured_client import UnstructuredClient, RetryConfig
6-
from unstructured_client.utils import BackoffStrategy
7-
8-
FAKE_API_KEY = "91pmLBeETAbXCpNylRsLq11FdiZPTk"
9-
103

114
@pytest.fixture(scope="module")
125
def platform_api_url():
136
return "https://platform.unstructuredapp.io"
147

158

16-
@pytest.fixture(scope="module")
17-
def client(platform_api_url) -> UnstructuredClient:
18-
_client = UnstructuredClient(
19-
api_key_auth=FAKE_API_KEY,
20-
server_url=platform_api_url,
21-
retry_config=RetryConfig(
22-
strategy="backoff",
23-
retry_connection_errors=False,
24-
backoff=BackoffStrategy(
25-
max_elapsed_time=0, max_interval=0, exponent=0, initial_interval=0
26-
),
27-
),
28-
)
29-
yield _client

gen.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ python:
1919
deepdiff: '>=6.0'
2020
pytest: '>=8.3.3'
2121
pytest-asyncio: '>=0.24.0'
22+
pytest-freezgun: '>=0.4.2'
2223
pytest-mock: '>=3.14.0'
2324
types-aiofiles: '>=24.1.0'
2425
uvloop: '>=0.20.0'

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mypy = "==1.14.1"
3838
pylint = "==3.2.3"
3939
pytest = ">=8.3.3"
4040
pytest-asyncio = ">=0.24.0"
41+
pytest-freezgun = ">=0.4.2"
4142
pytest-mock = ">=3.14.0"
4243
types-aiofiles = ">=24.1.0"
4344
types-python-dateutil = "^2.9.0.20240316"

0 commit comments

Comments
 (0)