Issue #15828: Don't try to close a file if imp.find_module() doesn't

return one.
This commit is contained in:
Brett Cannon 2012-08-31 11:31:20 -04:00
parent 91b9f139bc
commit 848cdfdf97
1 changed files with 3 additions and 1 deletions

View File

@ -211,7 +211,9 @@ class ImportTests(unittest.TestCase):
# and importlib couldn't handle C extensions # and importlib couldn't handle C extensions
example = "_heapq" example = "_heapq"
x = imp.find_module(example) x = imp.find_module(example)
self.addCleanup(x[0].close) file_ = x[0]
if file_ is not None:
self.addCleanup(file_.close)
mod = imp.load_module(example, *x) mod = imp.load_module(example, *x)
self.assertEqual(mod.__name__, example) self.assertEqual(mod.__name__, example)