Commit 16a1f634 authored by Benjamin Peterson's avatar Benjamin Peterson

make file closing more robust

parent 94f55837
......@@ -46,13 +46,12 @@ class ImportTest(unittest.TestCase):
else:
pyc = TESTFN + ".pyc"
f = open(source, "w")
print("# This tests Python's ability to import a", ext, "file.", file=f)
a = random.randrange(1000)
b = random.randrange(1000)
print("a =", a, file=f)
print("b =", b, file=f)
f.close()
with open(source, "w") as f:
print("# This tests Python's ability to import a", ext, "file.", file=f)
a = random.randrange(1000)
b = random.randrange(1000)
print("a =", a, file=f)
print("b =", b, file=f)
if TESTFN in sys.modules:
del sys.modules[TESTFN]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment