summaryrefslogtreecommitdiff
path: root/tests/test_execfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_execfile.py')
-rw-r--r--tests/test_execfile.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py
index 3a92ff76..63fb919d 100644
--- a/tests/test_execfile.py
+++ b/tests/test_execfile.py
@@ -66,7 +66,8 @@ class RunFileTest(CoverageTest):
a = 1
print("a is %r" % a)
#""")
- abrupt = open("abrupt.py").read()
+ with open("abrupt.py") as f:
+ abrupt = f.read()
self.assertEqual(abrupt[-1], '#')
run_python_file("abrupt.py", ["abrupt.py"])
self.assertEqual(self.stdout(), "a is 1\n")
@@ -113,10 +114,9 @@ class RunPycFileTest(CoverageTest):
pycfile = self.make_pyc()
# Jam Python 2.1 magic number into the .pyc file.
- fpyc = open(pycfile, "r+b")
- fpyc.seek(0)
- fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))
- fpyc.close()
+ with open(pycfile, "r+b") as fpyc:
+ fpyc.seek(0)
+ fpyc.write(binary_bytes([0x2a, 0xeb, 0x0d, 0x0a]))
with self.assertRaisesRegex(NoCode, "Bad magic number in .pyc file"):
run_python_file(pycfile, [pycfile])