Skip to content

Commit

Permalink
Close files in the module_loading tests always.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaynor committed Aug 15, 2012
1 parent ebc1325 commit ca6015c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/regressiontests/utils/module_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ def __init__(self):
def find_module(self, fullname, path=None):
tail = fullname.rsplit('.', 1)[-1]
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:
return None
else:
Expand All @@ -119,7 +124,11 @@ def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
fd, fn, info = self._cache[fullname]
return imp.load_module(fullname, fd, fn, info)
try:
return imp.load_module(fullname, fd, fn, info)
finally:
if fd:
fd.close()

class TestFinder(object):
def __init__(self, *args, **kwargs):
Expand Down

0 comments on commit ca6015c

Please sign in to comment.