mirror of
https://github.com/python/cpython.git
synced 2024-11-25 02:44:06 +08:00
make file closing more robust
This commit is contained in:
parent
94f5583777
commit
16a1f6343f
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user