diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2014-09-15 11:50:44 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2014-09-15 11:50:44 (GMT) |
commit | 8fad1676a215bab3e61dccf0f1802ccb17a43a41 (patch) | |
tree | 8a372bcba4c55571779e527d4c202bc2ab04ea0b /Lib/test | |
parent | b85a97600a45bf235fd8b541ebab358f6a8aa5dd (diff) | |
download | cpython-8fad1676a215bab3e61dccf0f1802ccb17a43a41.zip cpython-8fad1676a215bab3e61dccf0f1802ccb17a43a41.tar.gz cpython-8fad1676a215bab3e61dccf0f1802ccb17a43a41.tar.bz2 |
Issue #22166: clear codec caches in test_codecs
Diffstat (limited to 'Lib/test')
-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 9b62d5b..856126c 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2578,6 +2578,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): @@ -2603,6 +2611,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, |