Skip to content

Commit fdaf84a

Browse files
committed
[NRL-1470] Add warning/error logging to test client retries
1 parent cc5f23b commit fdaf84a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/utilities/api_clients.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
from typing import Any, Callable
34

45
import requests
@@ -8,6 +9,8 @@
89
from nrlf.core.constants import Categories, PointerTypes
910
from nrlf.core.model import ConnectionMetadata
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
class ClientConfig(BaseModel):
1316
base_url: str
@@ -44,18 +47,16 @@ def retry_if(status_codes: list[int]) -> Callable[..., Any]:
4447
def wrapped_func(func: Callable[..., Response]) -> Callable[..., Response]:
4548
def wrapper(*args: Any, **kwargs: Any) -> Any:
4649
attempt_responses: list[Response] = []
47-
for attempt in range(2):
50+
for attempt in range(3):
4851
response = func(*args, **kwargs)
4952
if not response.status_code or response.status_code not in status_codes:
5053
return response
5154
attempt_responses.append(response)
52-
print( # noqa: T201
53-
f"Retrying due to {response.status_code} error in attempt {attempt + 1}..."
55+
logger.warning(
56+
f"Attempt {attempt + 1} failed with status code {response.status_code}"
5457
)
5558

56-
print( # noqa: T201
57-
f"All attempts failed with responses: {attempt_responses}"
58-
)
59+
logger.error(f"All attempts failed with responses: {attempt_responses}")
5960
raise RuntimeError(
6061
f"Function failed after retries with responses: {attempt_responses}"
6162
)

0 commit comments

Comments
 (0)