[Python-3000-checkins] r65723 - python/branches/py3k/Lib/test/test_os.py

antoine.pitrou python-3000-checkins at python.org
Sun Aug 17 00:03:18 CEST 2008


Author: antoine.pitrou
Date: Sun Aug 17 00:03:17 2008
New Revision: 65723

Log:
#3571: try to fix recurrent buildbot failures by strenghtening test_os.test_closerange



Modified:
   python/branches/py3k/Lib/test/test_os.py

Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py	(original)
+++ python/branches/py3k/Lib/test/test_os.py	Sun Aug 17 00:03:17 2008
@@ -21,10 +21,27 @@
         self.assert_(os.access(support.TESTFN, os.W_OK))
 
     def test_closerange(self):
-        f = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
+        first = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR)
+        # We must allocate two consecutive file descriptors, otherwise
+        # it will mess up other file descriptors (perhaps even the three
+        # standard ones).
+        second = os.dup(first)
+        try:
+            retries = 0
+            while second != first + 1:
+                os.close(first)
+                retries += 1
+                if retries > 10:
+                    # XXX test skipped
+                    print("couldn't allocate two consecutive fds, "
+                        "skipping test_closerange", file=sys.stderr)
+                    return
+                first, second = second, os.dup(second)
+        finally:
+            os.close(second)
         # close a fd that is open, and one that isn't
-        os.closerange(f, f+2)
-        self.assertRaises(OSError, os.write, f, "a")
+        os.closerange(first, first + 2)
+        self.assertRaises(OSError, os.write, first, "a")
 
 class TemporaryFileTests(unittest.TestCase):
     def setUp(self):


More information about the Python-3000-checkins mailing list