summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-11-13 16:31:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-11-13 16:31:51 (GMT)
commitca154091950023d209819484d2d5c51ddcc1e882 (patch)
tree17e87f66d5f4a67c87e3e9f016dee4783e67d53a /Lib/test/support.py
parent8f6713f46d774942beb7984792a7a4c8666aab9a (diff)
downloadcpython-ca154091950023d209819484d2d5c51ddcc1e882.zip
cpython-ca154091950023d209819484d2d5c51ddcc1e882.tar.gz
cpython-ca154091950023d209819484d2d5c51ddcc1e882.tar.bz2
Merged revisions 76240 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r76240 | antoine.pitrou | 2009-11-13 17:29:04 +0100 (ven., 13 nov. 2009) | 6 lines Issue #6551: test_zipimport could import and then destroy some modules of the encodings package, which would make other tests fail further down the road because the internally cached encoders and decoders would point to empty global variables. ........
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 5672a20..18fb391 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -919,6 +919,23 @@ def run_doctest(module, verbosity=None):
(module.__name__, t))
return f, t
+
+#=======================================================================
+# Support for saving and restoring the imported modules.
+
+def modules_setup():
+ return sys.modules.copy(),
+
+def modules_cleanup(oldmodules):
+ # Encoders/decoders are registered permanently within the internal
+ # codec cache. If we destroy the corresponding modules their
+ # globals will be set to None which will trip up the cached functions.
+ encodings = [(k, v) for k, v in sys.modules.items()
+ if k.startswith('encodings.')]
+ sys.modules.clear()
+ sys.modules.update(encodings)
+ sys.modules.update(oldmodules)
+
#=======================================================================
# Threading support to prevent reporting refleaks when running regrtest.py -R