Use setUp and tearDown to manage test file.
authorEmil Mikulic <emikulic@gmail.com>
Sun, 17 Apr 2011 09:01:52 +0000 (19:01 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 10:56:14 +0000 (20:56 +1000)
devel/test.py

index ad6163c..8aedb4d 100755 (executable)
@@ -72,13 +72,15 @@ class TestHelper(unittest.TestCase):
             'Generated by darkhttpd')
 
 class TestDirList(TestHelper):
+    def setUp(self):
+        self.fn = WWWROOT+"/escape#this"
+        open(self.fn, "w").write("x"*12345)
+
+    def tearDown(self):
+        os.unlink(self.fn)
+
     def test_dirlist_escape(self):
-        fn = WWWROOT+"/escape#this"
-        open(fn, "w").write("x"*12345)
-        try:
-            resp = Conn().get("/")
-        finally:
-            os.unlink(fn)
+        resp = Conn().get("/")
         status, hdrs, body = parse(resp)
         self.assertEquals(ord("#"), 0x23)
         self.assertContains(body, "escape%23this", "12345")