[Python-checkins] r42357 - python/trunk/Lib/test/test_file.py

tim.peters python-checkins at python.org
Tue Feb 14 18:41:19 CET 2006


Author: tim.peters
Date: Tue Feb 14 18:41:18 2006
New Revision: 42357

Modified:
   python/trunk/Lib/test/test_file.py
Log:
New test code failed to close the file.  This caused
test_file to fail on Windows in reality (can't delete
a still-open file), but a new bare "except:" hid that
test_file failed on Windows, and leaving behind the
still-open TESTFN caused a cascade of bogus failures
in later tests.

So, close the file, and stop hiding failure to unlink.


Modified: python/trunk/Lib/test/test_file.py
==============================================================================
--- python/trunk/Lib/test/test_file.py	(original)
+++ python/trunk/Lib/test/test_file.py	Tue Feb 14 18:41:18 2006
@@ -323,18 +323,17 @@
                          "failed. Got %r, expected %r" % (line, testline))
     # Reading after iteration hit EOF shouldn't hurt either
     f = open(TESTFN)
-    for line in f:
-        pass
     try:
-        f.readline()
-        f.readinto(buf)
-        f.read()
-        f.readlines()
-    except ValueError:
-        raise TestFailed("read* failed after next() consumed file")
+        for line in f:
+            pass
+        try:
+            f.readline()
+            f.readinto(buf)
+            f.read()
+            f.readlines()
+        except ValueError:
+            raise TestFailed("read* failed after next() consumed file")
+    finally:
+        f.close()
 finally:
-    # Bare 'except' so as not to mask errors in the test
-    try:
-        os.unlink(TESTFN)
-    except:
-        pass
+    os.unlink(TESTFN)


More information about the Python-checkins mailing list