Skip to content

Commit 7f725a7

Browse files
committed
add unit_test for custom session retries
1 parent d277a96 commit 7f725a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/unit/core_python/test_session.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import requests
1212
import responses
1313
from requests.adapters import HTTPAdapter
14+
from requests.exceptions import RetryError
1415
from responses import registries
1516
from urllib3.util.retry import Retry
1617

@@ -34,6 +35,23 @@ def test_retry(url):
3435
assert len(responses.calls) == 6
3536

3637

38+
@pytest.mark.parametrize(
39+
("url", "retries"), [("https://api.example.com/retry", 1), ("http://api.example.com/retry", 0)]
40+
)
41+
@responses.activate(registry=registries.OrderedRegistry)
42+
def test_custom_retry(url, retries):
43+
"""
44+
测试自定义重试次数
45+
"""
46+
47+
[responses.add(responses.POST, url, body="Error", status=500) for _ in range(2)]
48+
s = create_session()
49+
with pytest.raises(RetryError):
50+
s.post(url, retries=retries)
51+
52+
assert len(responses.calls) == retries + 1
53+
54+
3755
@responses.activate(registry=registries.OrderedRegistry)
3856
def test_session_headers():
3957
"""

0 commit comments

Comments
 (0)