diff options
Diffstat (limited to 'Lib/test/test_codecs.py')
| -rw-r--r-- | Lib/test/test_codecs.py | 14 | 
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index f59c37d..c1f54ec 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2586,6 +2586,14 @@ def _get_test_codec(codec_name):      return _TEST_CODECS.get(codec_name)  codecs.register(_get_test_codec) # Returns None, not usable as a decorator +try: +    # Issue #22166: Also need to clear the internal cache in CPython +    from _codecs import _forget_codec +except ImportError: +    def _forget_codec(codec_name): +        pass + +  class ExceptionChainingTest(unittest.TestCase):      def setUp(self): @@ -2611,6 +2619,12 @@ class ExceptionChainingTest(unittest.TestCase):      def tearDown(self):          _TEST_CODECS.pop(self.codec_name, None) +        # Issue #22166: Also pop from caches to avoid appearance of ref leaks +        encodings._cache.pop(self.codec_name, None) +        try: +            _forget_codec(self.codec_name) +        except KeyError: +            pass      def set_codec(self, encode, decode):          codec_info = codecs.CodecInfo(encode, decode,  | 
