summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-11-05 01:26:57 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-11-05 01:26:57 (GMT)
commitcfed029c42ba1f1129de0ff3e455fcaf1c7ef9c6 (patch)
tree1f73f59b1b2b46fc31074f917bfd12f81dd93c6d
parent0ae45116245d4b508672d87eb1249cbf0079f167 (diff)
downloadcpython-cfed029c42ba1f1129de0ff3e455fcaf1c7ef9c6.zip
cpython-cfed029c42ba1f1129de0ff3e455fcaf1c7ef9c6.tar.gz
cpython-cfed029c42ba1f1129de0ff3e455fcaf1c7ef9c6.tar.bz2
Use tempfile.mkdtemp() instead of tempfile.tempdir for where importlib places
source files for tests. Allows for concurrent execution of the tests by preventing various executions from trampling each other. Closes issue #7248.
-rw-r--r--Lib/importlib/test/source/util.py15
-rw-r--r--Misc/NEWS4
2 files changed, 8 insertions, 11 deletions
diff --git a/Lib/importlib/test/source/util.py b/Lib/importlib/test/source/util.py
index a881d4a..2b945c5 100644
--- a/Lib/importlib/test/source/util.py
+++ b/Lib/importlib/test/source/util.py
@@ -42,8 +42,8 @@ def create_modules(*names):
that contains the name passed into the context manager that caused the
creation of the module.
- All files are created in a temporary directory specified by
- tempfile.gettempdir(). This directory is inserted at the beginning of
+ All files are created in a temporary directory returned by
+ tempfile.mkdtemp(). This directory is inserted at the beginning of
sys.path. When the context manager exits all created files (source and
bytecode) are explicitly deleted.
@@ -58,7 +58,7 @@ def create_modules(*names):
state_manager = None
uncache_manager = None
try:
- temp_dir = tempfile.gettempdir()
+ temp_dir = tempfile.mkdtemp()
mapping['.root'] = temp_dir
import_names = set()
for name in names:
@@ -91,11 +91,4 @@ def create_modules(*names):
state_manager.__exit__(None, None, None)
if uncache_manager is not None:
uncache_manager.__exit__(None, None, None)
- # Reverse the order for path removal to unroll directory creation.
- for path in reversed(created_paths):
- if file_path.endswith('.py'):
- support.unlink(path)
- support.unlink(path + 'c')
- support.unlink(path + 'o')
- else:
- os.rmdir(path)
+ support.rmtree(temp_dir)
diff --git a/Misc/NEWS b/Misc/NEWS
index f114efb..1e2a79f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -354,6 +354,10 @@ Documentation
Tests
-----
+- Issue #7248 (part 2): Use a unique temporary directory for importlib source
+ tests instead of tempfile.tempdir. This prevents the tests from sharing state
+ between concurrent executions on the same system.
+
- Issue #7248: In importlib.test.source.util a try/finally block did not make
sure that some referenced objects actually were created in the block before
calling methods on the object.