summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-08-16 22:03:17 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2008-08-16 22:03:17 (GMT)
commitb9ee06c26b73056802868c7ea0efb507ccbfa09f (patch)
treeb5d1a45713b88adf4d03316f8f6d216d7bafec20 /Lib/test/test_os.py
parenta307d0fc41587da8cc2600ce5098fcf491740c8b (diff)
downloadcpython-b9ee06c26b73056802868c7ea0efb507ccbfa09f.zip
cpython-b9ee06c26b73056802868c7ea0efb507ccbfa09f.tar.gz
cpython-b9ee06c26b73056802868c7ea0efb507ccbfa09f.tar.bz2
#3571: try to fix recurrent buildbot failures by strenghtening test_os.test_closerange
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 09270e1..ca23dba 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -21,10 +21,27 @@ class FileTests(unittest.TestCase):
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):