summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2008-02-24 18:47:03 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2008-02-24 18:47:03 (GMT)
commit6057b2e645dd3b7a262553d5a547ef45d3fc5d93 (patch)
tree2cc98747bc937c53e079e115fa98ee39cddb447f /Lib/test
parent6a123cb7827859748a0096570dfbb5ceba0e59dc (diff)
downloadcpython-6057b2e645dd3b7a262553d5a547ef45d3fc5d93.zip
cpython-6057b2e645dd3b7a262553d5a547ef45d3fc5d93.tar.gz
cpython-6057b2e645dd3b7a262553d5a547ef45d3fc5d93.tar.bz2
Create a db_home directory with a unique name so multiple users can
run the test simultaneously. The simplest thing I found that worked on both Windows and Unix was to use the PID. It's unique so should be sufficient. This should prevent many of the spurious failures of the automated tests since they run as different users. Also cleanup the directory consistenly in the tearDown methods. It would be nice if someone ensured that the directories are always created with a consistent name.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_bsddb3.py13
-rw-r--r--Lib/test/test_support.py9
2 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_bsddb3.py b/Lib/test/test_bsddb3.py
index 5a4258e..27a0900 100644
--- a/Lib/test/test_bsddb3.py
+++ b/Lib/test/test_bsddb3.py
@@ -2,10 +2,12 @@
"""
Run all test cases.
"""
+import os
import sys
+import tempfile
import time
import unittest
-from test.test_support import requires, verbose, run_unittest, unlink
+from test.test_support import requires, verbose, run_unittest, unlink, rmtree
# When running as a script instead of within the regrtest framework, skip the
# requires test, since it's obvious we want to run them.
@@ -85,6 +87,15 @@ def suite():
# For invocation through regrtest
def test_main():
run_unittest(suite())
+ db_home = os.path.join(tempfile.gettempdir(), 'db_home')
+ # The only reason to remove db_home is in case if there is an old
+ # one lying around. This might be by a different user, so just
+ # ignore errors. We should always make a unique name now.
+ try:
+ rmtree(db_home)
+ except:
+ pass
+ rmtree('db_home%d' % os.getpid())
# For invocation as a script
if __name__ == '__main__':
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index d36d81c..2071606 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -9,6 +9,7 @@ import socket
import sys
import os
import os.path
+import shutil
import warnings
import unittest
@@ -64,6 +65,14 @@ def unlink(filename):
except OSError:
pass
+def rmtree(path):
+ try:
+ shutil.rmtree(path)
+ except OSError, e:
+ # Unix returns ENOENT, Windows returns ESRCH.
+ if e.errno not in (errno.ENOENT, errno.ESRCH):
+ raise
+
def forget(modname):
'''"Forget" a module was ever imported by removing it from sys.modules and
deleting any .pyc and .pyo files.'''