summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2011-03-15 17:38:22 -0400
committerBrett Cannon <brett@python.org>2011-03-15 17:38:22 -0400
commitb637680f7e4e23c59c12dd5f95c78b75a51e75f4 (patch)
treef488e63022315a09cdab14d1aba5a70060c2c1b3
parentee877a08e92bb31258db536293b0d5f9b26b679b (diff)
downloadcpython-git-b637680f7e4e23c59c12dd5f95c78b75a51e75f4.tar.gz
Properly close a file in test_os.
-rw-r--r--Lib/test/test_os.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 8161d9b03b..e40f763af1 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1528,18 +1528,16 @@ class TestSendfile(unittest.TestCase):
def test_trailers(self):
TESTFN2 = support.TESTFN + "2"
- f = open(TESTFN2, 'wb')
- f.write(b"abcde")
- f.close()
- f = open(TESTFN2, 'rb')
- try:
- os.sendfile(self.sockno, f.fileno(), 0, 4096, trailers=[b"12345"])
+ with open(TESTFN2, 'wb') as f:
+ f.write(b"abcde")
+ with open(TESTFN2, 'rb')as f:
+ self.addCleanup(os.remove, TESTFN2)
+ os.sendfile(self.sockno, f.fileno(), 0, 4096,
+ trailers=[b"12345"])
self.client.close()
self.server.wait()
data = self.server.handler_instance.get_data()
self.assertEqual(data, b"abcde12345")
- finally:
- os.remove(TESTFN2)
if hasattr(os, "SF_NODISKIO"):
def test_flags(self):