Close files in the module_loading tests always.

This commit is contained in:
Alex Gaynor 2012-08-15 02:47:02 -07:00
parent ebc1325721
commit ca6015ca71
1 changed files with 11 additions and 2 deletions

View File

@ -109,7 +109,12 @@ class ProxyFinder(object):
def find_module(self, fullname, path=None): def find_module(self, fullname, path=None):
tail = fullname.rsplit('.', 1)[-1] tail = fullname.rsplit('.', 1)[-1]
try: try:
self._cache[fullname] = imp.find_module(tail, path) fd, fn, info = imp.find_module(tail, path)
if fullname in self._cache:
old_fd = self._cache[fullname][0]
if old_fd:
old_fd.close()
self._cache[fullname] = (fd, fn, info)
except ImportError: except ImportError:
return None return None
else: else:
@ -119,7 +124,11 @@ class ProxyFinder(object):
if fullname in sys.modules: if fullname in sys.modules:
return sys.modules[fullname] return sys.modules[fullname]
fd, fn, info = self._cache[fullname] fd, fn, info = self._cache[fullname]
try:
return imp.load_module(fullname, fd, fn, info) return imp.load_module(fullname, fd, fn, info)
finally:
if fd:
fd.close()
class TestFinder(object): class TestFinder(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):