File tree Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,25 @@ def clear_caches():
294294 else :
295295 importlib_metadata .FastPath .__new__ .cache_clear ()
296296
297+ try :
298+ encodings = sys .modules ['encodings' ]
299+ except KeyError :
300+ pass
301+ else :
302+ encodings ._cache .clear ()
303+
304+ try :
305+ codecs = sys .modules ['codecs' ]
306+ except KeyError :
307+ pass
308+ else :
309+ # There's no direct API to clear the codecs search cache, but
310+ # `unregister` clears it implicitly.
311+ def noop_search_function (name ):
312+ return None
313+ codecs .register (noop_search_function )
314+ codecs .unregister (noop_search_function )
315+
297316
298317def get_build_info ():
299318 # Get most important configure and build options as a list of strings.
Original file line number Diff line number Diff line change 1313
1414from test import support
1515from test .support import os_helper
16+ from test .support import warnings_helper
1617
1718try :
1819 import _testlimitedcapi
@@ -3902,8 +3903,8 @@ def test_encodings_normalize_encoding(self):
39023903 self .assertEqual (normalize ('utf...8' ), 'utf...8' )
39033904
39043905 # Non-ASCII *encoding* is deprecated.
3905- with self . assertWarnsRegex ( DeprecationWarning ,
3906- "Support for non-ascii encoding names will be removed in 3.17" ):
3906+ msg = "Support for non-ascii encoding names will be removed in 3.17"
3907+ with warnings_helper . check_warnings (( msg , DeprecationWarning ) ):
39073908 self .assertEqual (normalize ('utf\xE9 \u20AC \U0010ffff -8' ), 'utf_8' )
39083909
39093910
Original file line number Diff line number Diff line change 4141
4242from test import support
4343from test .support import threading_helper
44+ from test .support import warnings_helper
4445from test .support .os_helper import unlink
4546from test .test_email import openfile , TestEmailBase
4647
@@ -5738,7 +5739,7 @@ def test_rfc2231_bad_character_in_encoding(self):
57385739
57395740"""
57405741 msg = email .message_from_string (m )
5741- with self . assertWarns ( DeprecationWarning ):
5742+ with warnings_helper . check_warnings (( '' , DeprecationWarning ) ):
57425743 self .assertEqual (msg .get_filename (), 'myfile.txt' )
57435744
57445745 def test_rfc2231_single_tick_in_filename_extended (self ):
Original file line number Diff line number Diff line change 88from email import headerregistry
99from email .headerregistry import Address , Group
1010from test .support import ALWAYS_EQ
11+ from test .support import warnings_helper
1112
1213
1314DITTO = object ()
@@ -252,7 +253,7 @@ def content_type_as_value(self,
252253 if 'utf-8%E2%80%9D' in source and 'ascii' not in source :
253254 import encodings
254255 encodings ._cache .clear ()
255- with self . assertWarns ( DeprecationWarning ):
256+ with warnings_helper . check_warnings (( '' , DeprecationWarning ) ):
256257 h = self .make_header ('Content-Type' , source )
257258 else :
258259 h = self .make_header ('Content-Type' , source )
You can’t perform that action at this time.
0 commit comments