File tree Expand file tree Collapse file tree 7 files changed +39
-4
lines changed Expand file tree Collapse file tree 7 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 4141 SCW_DEFAULT_PROJECT_ID : ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
4242 SCW_DEFAULT_ORGANIZATION_ID : ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
4343 SCW_DEFAULT_REGION : ${{ secrets.SCW_DEFAULT_REGION }}
44- run : poetry run python -m unittest discover -s tests -v
45-
44+ run : poetry run pytest --record-mode=none
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ ruff = ">=0.5.0,<0.12.9"
3232mypy = " ^1.5.1"
3333ty = " ^0.0.1a15"
3434pyrefly = " >=0.24.2,<0.27.0"
35+ pytest = " ^8.4.1"
36+ pytest-recording = " ^0.13.4"
3537
3638[build-system ]
3739requires = [" poetry-core" ]
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ ruff = ">=0.5.0,<0.12.8"
3434mypy = " ^1.5.1"
3535ty = " ^0.0.1a15"
3636pyrefly = " >=0.24.2,<0.27.0"
37+ pytest = " ^8.4.1"
3738
3839[build-system ]
3940requires = [" poetry-core" ]
Original file line number Diff line number Diff line change 1414
1515Params = Mapping [str , Any ]
1616
17+ from requests .adapters import HTTPAdapter
18+ from urllib3 .util import Retry
19+
20+
1721
1822@dataclass
1923class APILogger :
@@ -154,6 +158,20 @@ def _request(
154158
155159 logger = APILogger (self ._log , self .client ._increment_request_count ())
156160
161+ # define the retry strategy
162+ retry_strategy = Retry (
163+ total = 3 , # maximum number of retries
164+ status_forcelist = [
165+ 500 ,
166+ ], # the HTTP status codes to retry on
167+ )
168+
169+ # create an HTTP adapter with the retry strategy and mount it to the session
170+ adapter = HTTPAdapter (max_retries = retry_strategy )
171+ # create a new session object
172+ session = requests .Session ()
173+ session .mount ("https://" , adapter )
174+
157175 logger .log_request (
158176 method = method ,
159177 url = url ,
@@ -163,7 +181,7 @@ def _request(
163181 if isinstance (raw_body , bytes )
164182 else raw_body ,
165183 )
166- response = requests .request (
184+ response = session .request (
167185 method = method ,
168186 url = url ,
169187 params = request_params ,
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ ruff = ">=0.5.0,<0.12.9"
3333mypy = " ^1.5.1"
3434ty = " ^0.0.1a15"
3535pyrefly = " >=0.24.2,<0.27.0"
36+ pytest = " ^8.4.1"
37+ pytest-recording = " ^0.13.4"
3638
3739[build-system ]
3840requires = [" poetry-core" ]
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+
4+ @pytest .fixture (scope = "session" )
5+ def vcr_config ():
6+ return {
7+ # Replace the Authorization request header with "DUMMY" in cassettes
8+ "filter_headers" : ["x-auth-token" ],
9+ }
Original file line number Diff line number Diff line change 11import unittest
2+
3+ import pytest
4+ from vcr .unittest import VCRTestCase
25from scaleway .vpc .v2 import VpcV2API
36from scaleway_core .api import ScalewayException
47from scaleway_core .client import Client
1013created_vpc_count = 1
1114
1215
13- class TestScalewayVPCV2 (unittest .TestCase ):
16+ @pytest .mark .vcr ()
17+ class TestScalewayVPCV2 (VCRTestCase ):
1418 @classmethod
1519 def setUpClass (self ):
1620 self .client = Client .from_config_file_and_env ()
You can’t perform that action at this time.
0 commit comments