Skip to content

chore: add support for vcr.py #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ jobs:
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
SCW_DEFAULT_REGION: ${{ secrets.SCW_DEFAULT_REGION }}
run: poetry run python -m unittest discover -s tests -v

run: poetry run pytest --record-mode=none
618 changes: 615 additions & 3 deletions scaleway-async/poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions scaleway-async/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ruff = ">=0.5.0,<0.12.9"
mypy = "^1.5.1"
ty = "^0.0.1a15"
pyrefly = ">=0.24.2,<0.27.0"
pytest = "^8.4.1"
pytest-recording = "^0.13.4"

[build-system]
requires = ["poetry-core"]
Expand Down
113 changes: 112 additions & 1 deletion scaleway-core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scaleway-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ruff = ">=0.5.0,<0.12.8"
mypy = "^1.5.1"
ty = "^0.0.1a15"
pyrefly = ">=0.24.2,<0.27.0"
pytest = "^8.4.1"

[build-system]
requires = ["poetry-core"]
Expand Down
18 changes: 17 additions & 1 deletion scaleway-core/scaleway_core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import logging
from dataclasses import dataclass
from typing import IO, Any, Dict, Iterable, List, Mapping, Optional, Tuple, Union
from urllib3.util import Retry

import requests
from requests import Response
from requests.adapters import HTTPAdapter

from .client import Client

Expand Down Expand Up @@ -154,6 +156,20 @@ def _request(

logger = APILogger(self._log, self.client._increment_request_count())

# define the retry strategy
retry_strategy = Retry(
total=3, # maximum number of retries
status_forcelist=[
500,
], # the HTTP status codes to retry on
)

# create an HTTP adapter with the retry strategy and mount it to the session
adapter = HTTPAdapter(max_retries=retry_strategy)
# create a new session object
session = requests.Session()
session.mount("https://", adapter)

logger.log_request(
method=method,
url=url,
Expand All @@ -163,7 +179,7 @@ def _request(
if isinstance(raw_body, bytes)
else raw_body,
)
response = requests.request(
response = session.request(
method=method,
url=url,
params=request_params,
Expand Down
Loading
Loading