]> granicus.if.org Git - python/commitdiff
Fix SF # 631066, running regrtest in user mode fails
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 3 Nov 2002 00:35:53 +0000 (00:35 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 3 Nov 2002 00:35:53 +0000 (00:35 +0000)
Try to write to TESTFN, if that fails, try TESTFN in /tmp
If that fails, print a warning and go on.
Will backport.

Lib/test/test_support.py

index c720f433629aa5ee60f42b2292421b93c1c793c8..8aab9de4586db6301b557189c84b878f4fbd0b94 100644 (file)
@@ -97,7 +97,27 @@ elif os.name != 'riscos':
             TESTFN_ENCODING="mbcs"
 else:
     TESTFN = 'test'
-del os
+
+# Make sure we can write to TESTFN, try in /tmp if we can't
+fp = None
+try:
+    fp = open(TESTFN, 'w+')
+except IOError:
+    TMP_TESTFN = os.path.join('/tmp', TESTFN)
+    try:
+        fp = open(TMP_TESTFN, 'w+')
+        TESTFN = TMP_TESTFN
+        del TMP_TESTFN
+    except IOError:
+        print ('WARNING: tests will fail, unable to write to: %s or %s' % 
+                (TESTFN, TMP_TESTFN))
+if fp is not None:
+    fp.close()
+    try:
+        os.unlink(TESTFN)
+    except:
+        pass
+del os, fp
 
 from os import unlink