@@ -26,13 +26,15 @@ def test_ssl_with_invalid_cert(self, request):
2626 sslclient = redis .from_url (ssl_url )
2727 with pytest .raises (ConnectionError ) as e :
2828 sslclient .ping ()
29- assert "SSL: CERTIFICATE_VERIFY_FAILED" in str (e )
29+ assert "SSL: CERTIFICATE_VERIFY_FAILED" in str (e )
30+ sslclient .close ()
3031
3132 def test_ssl_connection (self , request ):
3233 ssl_url = request .config .option .redis_ssl_url
3334 p = urlparse (ssl_url )[1 ].split (":" )
3435 r = redis .Redis (host = p [0 ], port = p [1 ], ssl = True , ssl_cert_reqs = "none" )
3536 assert r .ping ()
37+ r .close ()
3638
3739 def test_ssl_connection_without_ssl (self , request ):
3840 ssl_url = request .config .option .redis_ssl_url
@@ -41,7 +43,8 @@ def test_ssl_connection_without_ssl(self, request):
4143
4244 with pytest .raises (ConnectionError ) as e :
4345 r .ping ()
44- assert "Connection closed by server" in str (e )
46+ assert "Connection closed by server" in str (e )
47+ r .close ()
4548
4649 def test_validating_self_signed_certificate (self , request ):
4750 ssl_url = request .config .option .redis_ssl_url
@@ -56,6 +59,7 @@ def test_validating_self_signed_certificate(self, request):
5659 ssl_ca_certs = self .SERVER_CERT ,
5760 )
5861 assert r .ping ()
62+ r .close ()
5963
6064 def test_validating_self_signed_string_certificate (self , request ):
6165 with open (self .SERVER_CERT ) as f :
@@ -72,6 +76,7 @@ def test_validating_self_signed_string_certificate(self, request):
7276 ssl_ca_data = cert_data ,
7377 )
7478 assert r .ping ()
79+ r .close ()
7580
7681 def _create_oscp_conn (self , request ):
7782 ssl_url = request .config .option .redis_ssl_url
@@ -92,22 +97,25 @@ def _create_oscp_conn(self, request):
9297 def test_ssl_ocsp_called (self , request ):
9398 r = self ._create_oscp_conn (request )
9499 with pytest .raises (RedisError ) as e :
95- assert r .ping ()
96- assert "cryptography not installed" in str (e )
100+ r .ping ()
101+ assert "cryptography is not installed" in str (e )
102+ r .close ()
97103
98104 @skip_if_nocryptography ()
99105 def test_ssl_ocsp_called_withcrypto (self , request ):
100106 r = self ._create_oscp_conn (request )
101107 with pytest .raises (ConnectionError ) as e :
102108 assert r .ping ()
103- assert "No AIA information present in ssl certificate" in str (e )
109+ assert "No AIA information present in ssl certificate" in str (e )
110+ r .close ()
104111
105112 # rediss://, url based
106113 ssl_url = request .config .option .redis_ssl_url
107114 sslclient = redis .from_url (ssl_url )
108115 with pytest .raises (ConnectionError ) as e :
109116 sslclient .ping ()
110- assert "No AIA information present in ssl certificate" in str (e )
117+ assert "No AIA information present in ssl certificate" in str (e )
118+ sslclient .close ()
111119
112120 @skip_if_nocryptography ()
113121 def test_valid_ocsp_cert_http (self ):
@@ -132,7 +140,7 @@ def test_revoked_ocsp_certificate(self):
132140 ocsp = OCSPVerifier (wrapped , hostname , 443 )
133141 with pytest .raises (ConnectionError ) as e :
134142 assert ocsp .is_valid ()
135- assert "REVOKED" in str (e )
143+ assert "REVOKED" in str (e )
136144
137145 @skip_if_nocryptography ()
138146 def test_unauthorized_ocsp (self ):
@@ -157,7 +165,7 @@ def test_ocsp_not_present_in_response(self):
157165 ocsp = OCSPVerifier (wrapped , hostname , 443 )
158166 with pytest .raises (ConnectionError ) as e :
159167 assert ocsp .is_valid ()
160- assert "from the" in str (e )
168+ assert "from the" in str (e )
161169
162170 @skip_if_nocryptography ()
163171 def test_unauthorized_then_direct (self ):
@@ -193,6 +201,7 @@ def test_mock_ocsp_staple(self, request):
193201
194202 with pytest .raises (RedisError ):
195203 r .ping ()
204+ r .close ()
196205
197206 ctx = OpenSSL .SSL .Context (OpenSSL .SSL .SSLv23_METHOD )
198207 ctx .use_certificate_file (self .SERVER_CERT )
@@ -213,7 +222,8 @@ def test_mock_ocsp_staple(self, request):
213222
214223 with pytest .raises (ConnectionError ) as e :
215224 r .ping ()
216- assert "no ocsp response present" in str (e )
225+ assert "no ocsp response present" in str (e )
226+ r .close ()
217227
218228 r = redis .Redis (
219229 host = p [0 ],
@@ -228,4 +238,5 @@ def test_mock_ocsp_staple(self, request):
228238
229239 with pytest .raises (ConnectionError ) as e :
230240 r .ping ()
231- assert "no ocsp response present" in str (e )
241+ assert "no ocsp response present" in str (e )
242+ r .close ()
0 commit comments