@@ -79,6 +79,9 @@ def test_disconnect__close_OSError(self):
79
79
mock_sock .close .assert_called_once ()
80
80
assert conn ._sock is None
81
81
82
+ def clear (self , conn ):
83
+ conn .retry_on_error .clear ()
84
+
82
85
def test_retry_connect_on_timeout_error (self ):
83
86
"""Test that the _connect function is retried in case of a timeout"""
84
87
conn = Connection (retry_on_timeout = True , retry = Retry (NoBackoff (), 3 ))
@@ -95,6 +98,7 @@ def mock_connect():
95
98
conn ._connect .side_effect = mock_connect
96
99
conn .connect ()
97
100
assert conn ._connect .call_count == 3
101
+ self .clear (conn )
98
102
99
103
def test_connect_without_retry_on_os_error (self ):
100
104
"""Test that the _connect function is not being retried in case of a OSError"""
@@ -104,15 +108,17 @@ def test_connect_without_retry_on_os_error(self):
104
108
with pytest .raises (ConnectionError ):
105
109
conn .connect ()
106
110
assert _connect .call_count == 1
111
+ self .clear (conn )
107
112
108
113
def test_connect_timeout_error_without_retry (self ):
109
114
"""Test that the _connect function is not being retried if retry_on_timeout is
110
- set to False (default value) """
111
- conn = Connection ()
115
+ set to False"""
116
+ conn = Connection (retry_on_timeout = False )
112
117
conn ._connect = mock .Mock ()
113
118
conn ._connect .side_effect = socket .timeout
114
119
115
120
with pytest .raises (TimeoutError ) as e :
116
121
conn .connect ()
117
122
assert conn ._connect .call_count == 1
118
123
assert str (e .value ) == "Timeout connecting to server"
124
+ self .clear (conn )
0 commit comments