Skip to content

Commit 6db454d

Browse files
committed
refactor fail_sometimes
1 parent bf2903a commit 6db454d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/client/test_http.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import json
2323
import multiprocessing
24-
import os
24+
2525
import queue
2626
import random
2727
import socket
@@ -91,9 +91,12 @@ def duplicate_key_exception():
9191
return r
9292

9393

94-
def fail_sometimes(*args, **kwargs):
95-
# random.randint(1, 10) % 2:
96-
if random.randint(1, 100) % 10 == 0:
94+
def fail_sometimes(*args, **kwargs) -> MagicMock:
95+
"""
96+
Function that fails with a 50% chance. It either returns a successful mocked
97+
response or raises an urllib3 exception.
98+
"""
99+
if random.randint(1, 10) % 2:
97100
raise urllib3.exceptions.MaxRetryError(None, "/_sql", "")
98101
return fake_response(200)
99102

0 commit comments

Comments
 (0)