3131import platform
3232import sysconfig
3333import functools
34+ from contextlib import nullcontext
3435try :
3536 import ctypes
3637except ImportError :
@@ -2843,6 +2844,7 @@ def test_ssl_in_multiple_threads(self):
28432844 # See GH-124984: OpenSSL is not thread safe.
28442845 threads = []
28452846
2847+ warnings_filters = sys .flags .context_aware_warnings
28462848 global USE_SAME_TEST_CONTEXT
28472849 USE_SAME_TEST_CONTEXT = True
28482850 try :
@@ -2851,7 +2853,10 @@ def test_ssl_in_multiple_threads(self):
28512853 self .test_alpn_protocols ,
28522854 self .test_getpeercert ,
28532855 self .test_crl_check ,
2854- self .test_check_hostname_idn ,
2856+ functools .partial (
2857+ self .test_check_hostname_idn ,
2858+ warnings_filters = warnings_filters ,
2859+ ),
28552860 self .test_wrong_cert_tls12 ,
28562861 self .test_wrong_cert_tls13 ,
28572862 ):
@@ -3097,7 +3102,7 @@ def test_dual_rsa_ecc(self):
30973102 cipher = s .cipher ()[0 ].split ('-' )
30983103 self .assertTrue (cipher [:2 ], ('ECDHE' , 'ECDSA' ))
30993104
3100- def test_check_hostname_idn (self ):
3105+ def test_check_hostname_idn (self , warnings_filters = True ):
31013106 if support .verbose :
31023107 sys .stdout .write ("\n " )
31033108
@@ -3152,16 +3157,30 @@ def test_check_hostname_idn(self):
31523157 server_hostname = "python.example.org" ) as s :
31533158 with self .assertRaises (ssl .CertificateError ):
31543159 s .connect ((HOST , server .port ))
3155- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3156- with warnings_helper .check_no_resource_warning (self ):
3157- with self .assertRaises (UnicodeError ):
3158- context .wrap_socket (socket .socket (),
3159- server_hostname = '.pythontest.net' )
3160- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3161- with warnings_helper .check_no_resource_warning (self ):
3162- with self .assertRaises (UnicodeDecodeError ):
3163- context .wrap_socket (socket .socket (),
3164- server_hostname = b'k\xf6 nig.idn.pythontest.net' )
3160+ with (
3161+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3162+ (
3163+ warnings_helper .check_no_resource_warning (self )
3164+ if warnings_filters
3165+ else nullcontext ()
3166+ ),
3167+ self .assertRaises (UnicodeError ),
3168+ ):
3169+ context .wrap_socket (socket .socket (), server_hostname = '.pythontest.net' )
3170+
3171+ with (
3172+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3173+ (
3174+ warnings_helper .check_no_resource_warning (self )
3175+ if warnings_filters
3176+ else nullcontext ()
3177+ ),
3178+ self .assertRaises (UnicodeDecodeError ),
3179+ ):
3180+ context .wrap_socket (
3181+ socket .socket (),
3182+ server_hostname = b'k\xf6 nig.idn.pythontest.net' ,
3183+ )
31653184
31663185 def test_wrong_cert_tls12 (self ):
31673186 """Connecting when the server rejects the client's certificate
0 commit comments