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 41
41
SCW_DEFAULT_PROJECT_ID : ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
42
42
SCW_DEFAULT_ORGANIZATION_ID : ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
43
43
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"
32
32
mypy = " ^1.5.1"
33
33
ty = " ^0.0.1a15"
34
34
pyrefly = " >=0.24.2,<0.27.0"
35
+ pytest = " ^8.4.1"
36
+ pytest-recording = " ^0.13.4"
35
37
36
38
[build-system ]
37
39
requires = [" poetry-core" ]
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ ruff = ">=0.5.0,<0.12.8"
34
34
mypy = " ^1.5.1"
35
35
ty = " ^0.0.1a15"
36
36
pyrefly = " >=0.24.2,<0.27.0"
37
+ pytest = " ^8.4.1"
37
38
38
39
[build-system ]
39
40
requires = [" poetry-core" ]
Original file line number Diff line number Diff line change 14
14
15
15
Params = Mapping [str , Any ]
16
16
17
+ from requests .adapters import HTTPAdapter
18
+ from urllib3 .util import Retry
19
+
20
+
17
21
18
22
@dataclass
19
23
class APILogger :
@@ -154,6 +158,20 @@ def _request(
154
158
155
159
logger = APILogger (self ._log , self .client ._increment_request_count ())
156
160
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
+
157
175
logger .log_request (
158
176
method = method ,
159
177
url = url ,
@@ -163,7 +181,7 @@ def _request(
163
181
if isinstance (raw_body , bytes )
164
182
else raw_body ,
165
183
)
166
- response = requests .request (
184
+ response = session .request (
167
185
method = method ,
168
186
url = url ,
169
187
params = request_params ,
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ ruff = ">=0.5.0,<0.12.9"
33
33
mypy = " ^1.5.1"
34
34
ty = " ^0.0.1a15"
35
35
pyrefly = " >=0.24.2,<0.27.0"
36
+ pytest = " ^8.4.1"
37
+ pytest-recording = " ^0.13.4"
36
38
37
39
[build-system ]
38
40
requires = [" 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 1
1
import unittest
2
+
3
+ import pytest
4
+ from vcr .unittest import VCRTestCase
2
5
from scaleway .vpc .v2 import VpcV2API
3
6
from scaleway_core .api import ScalewayException
4
7
from scaleway_core .client import Client
10
13
created_vpc_count = 1
11
14
12
15
13
- class TestScalewayVPCV2 (unittest .TestCase ):
16
+ @pytest .mark .vcr ()
17
+ class TestScalewayVPCV2 (VCRTestCase ):
14
18
@classmethod
15
19
def setUpClass (self ):
16
20
self .client = Client .from_config_file_and_env ()
You can’t perform that action at this time.
0 commit comments