@@ -2754,29 +2754,14 @@ def test_uu_invalid(self):
2754
2754
2755
2755
def _get_test_codec (codec_name ):
2756
2756
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
2765
2757
2766
2758
2767
2759
class ExceptionChainingTest (unittest .TestCase ):
2768
2760
2769
2761
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 )
2780
2765
2781
2766
# We store the object to raise on the instance because of a bad
2782
2767
# interaction between the codec caching (which means we can't
@@ -2791,10 +2776,6 @@ def tearDown(self):
2791
2776
_TEST_CODECS .pop (self .codec_name , None )
2792
2777
# Issue #22166: Also pop from caches to avoid appearance of ref leaks
2793
2778
encodings ._cache .pop (self .codec_name , None )
2794
- try :
2795
- _forget_codec (self .codec_name )
2796
- except KeyError :
2797
- pass
2798
2779
2799
2780
def set_codec (self , encode , decode ):
2800
2781
codec_info = codecs .CodecInfo (encode , decode ,
0 commit comments