[Python-checkins] r65163 - python/trunk/Lib/test/test_importhooks.py
georg.brandl
python-checkins at python.org
Mon Jul 21 01:19:48 CEST 2008
Author: georg.brandl
Date: Mon Jul 21 01:18:55 2008
New Revision: 65163
Log:
Save the whole of sys.modules instead of using an import tracker.
This, when merged to py3k, will fix the spurious buildbot failure
in test_urllib2 ("<urlopen error unknown url type: do>").
Modified:
python/trunk/Lib/test/test_importhooks.py
Modified: python/trunk/Lib/test/test_importhooks.py
==============================================================================
--- python/trunk/Lib/test/test_importhooks.py (original)
+++ python/trunk/Lib/test/test_importhooks.py Mon Jul 21 01:18:55 2008
@@ -33,15 +33,6 @@
test_path = "!!!_test_!!!"
-class ImportTracker:
- """Importer that only tracks attempted imports."""
- def __init__(self):
- self.imports = []
- def find_module(self, fullname, path=None):
- self.imports.append(fullname)
- return None
-
-
class TestImporter:
modules = {
@@ -152,17 +143,15 @@
self.meta_path = sys.meta_path[:]
self.path_hooks = sys.path_hooks[:]
sys.path_importer_cache.clear()
- self.tracker = ImportTracker()
- sys.meta_path.insert(0, self.tracker)
+ self.modules_before = sys.modules.copy()
def tearDown(self):
sys.path[:] = self.path
sys.meta_path[:] = self.meta_path
sys.path_hooks[:] = self.path_hooks
sys.path_importer_cache.clear()
- for fullname in self.tracker.imports:
- if fullname in sys.modules:
- del sys.modules[fullname]
+ sys.modules.clear()
+ sys.modules.update(self.modules_before)
class ImportHooksTestCase(ImportHooksBaseTestCase):
@@ -261,13 +250,7 @@
for mname in mnames:
m = __import__(mname, globals(), locals(), ["__dummy__"])
m.__loader__ # to make sure we actually handled the import
- # Delete urllib from modules because urlparse was imported above.
- # Without this hack, test_socket_ssl fails if run in this order:
- # regrtest.py test_codecmaps_tw test_importhooks test_socket_ssl
- try:
- del sys.modules['urllib']
- except KeyError:
- pass
+
def test_main():
test_support.run_unittest(ImportHooksTestCase)
More information about the Python-checkins
mailing list