summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-08-31 11:31:20 -0400
committerBrett Cannon <brett@python.org>2012-08-31 11:31:20 -0400
commit848cdfdf97f3671f75aa98438f228e36e7d0a310 (patch)
tree107ad723bbb338cfe395f516151ce241b697de9d
parent91b9f139bc629e1ba931c60a3301e8062f6f4e6d (diff)
downloadcpython-git-848cdfdf97f3671f75aa98438f228e36e7d0a310.tar.gz
Issue #15828: Don't try to close a file if imp.find_module() doesn't
return one.
-rw-r--r--Lib/test/test_imp.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 20e5608e81..65c9f25c83 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -211,7 +211,9 @@ class ImportTests(unittest.TestCase):
# and importlib couldn't handle C extensions
example = "_heapq"
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)
self.assertEqual(mod.__name__, example)