@@ -2754,29 +2754,14 @@ def test_uu_invalid(self):
27542754
27552755def _get_test_codec (codec_name ):
27562756 return _TEST_CODECS .get (codec_name )
2757- codecs .register (_get_test_codec ) # Returns None, not usable as a decorator
2758-
2759- try :
2760- # Issue #22166: Also need to clear the internal cache in CPython
2761- from _codecs import _forget_codec
2762- except ImportError :
2763- def _forget_codec (codec_name ):
2764- pass
27652757
27662758
27672759class ExceptionChainingTest (unittest .TestCase ):
27682760
27692761 def setUp (self ):
2770- # There's no way to unregister a codec search function, so we just
2771- # ensure we render this one fairly harmless after the test
2772- # case finishes by using the test case repr as the codec name
2773- # The codecs module normalizes codec names, although this doesn't
2774- # appear to be formally documented...
2775- # We also make sure we use a truly unique id for the custom codec
2776- # to avoid issues with the codec cache when running these tests
2777- # multiple times (e.g. when hunting for refleaks)
2778- unique_id = repr (self ) + str (id (self ))
2779- self .codec_name = encodings .normalize_encoding (unique_id ).lower ()
2762+ self .codec_name = 'exception_chaining_test'
2763+ codecs .register (_get_test_codec )
2764+ self .addCleanup (codecs .unregister , _get_test_codec )
27802765
27812766 # We store the object to raise on the instance because of a bad
27822767 # interaction between the codec caching (which means we can't
@@ -2791,10 +2776,6 @@ def tearDown(self):
27912776 _TEST_CODECS .pop (self .codec_name , None )
27922777 # Issue #22166: Also pop from caches to avoid appearance of ref leaks
27932778 encodings ._cache .pop (self .codec_name , None )
2794- try :
2795- _forget_codec (self .codec_name )
2796- except KeyError :
2797- pass
27982779
27992780 def set_codec (self , encode , decode ):
28002781 codec_info = codecs .CodecInfo (encode , decode ,
0 commit comments