summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-06-04 18:35:18 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-09-09 23:01:15 +0200
commitd6be404e565fd04538ebc4771aa98422cc03fd2e (patch)
tree17269aeee27774da907527f283864ceba123be2c
parent0586c061f0b857e2259bea48e21ebb69a7878d13 (diff)
Changed strategy for removing TMPDIR in runtests.py.
Previously, a traceback would be displayed on exit because: - using some multiprocessing features creates a temporary directory - this directory would be inside TMPDIR - multiprocessing would attempt to remove it when a particular object was deallocated, after runtests.py had already removed it along with everything else in TMPDIR.
-rwxr-xr-xtests/runtests.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/runtests.py b/tests/runtests.py
index 095a9db8df..58181a0e92 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+import atexit
import logging
import os
import shutil
@@ -35,6 +36,12 @@ TMPDIR = tempfile.mkdtemp(prefix='django_')
# so that children processes inherit it.
tempfile.tempdir = os.environ['TMPDIR'] = TMPDIR
+# Removing the temporary TMPDIR. Ensure we pass in unicode so that it will
+# successfully remove temp trees containing non-ASCII filenames on Windows.
+# (We're assuming the temp dir name itself only contains ASCII characters.)
+atexit.register(shutil.rmtree, six.text_type(TMPDIR))
+
+
SUBDIRS_TO_SKIP = [
'data',
'import_error_package',
@@ -220,15 +227,6 @@ def setup(verbosity, test_labels, parallel):
def teardown(state):
- try:
- # Removing the temporary TMPDIR. Ensure we pass in unicode
- # so that it will successfully remove temp trees containing
- # non-ASCII filenames on Windows. (We're assuming the temp dir
- # name itself does not contain non-ASCII characters.)
- shutil.rmtree(six.text_type(TMPDIR))
- except OSError:
- print('Failed to remove temp directory: %s' % TMPDIR)
-
# Restore the old settings.
for key, value in state.items():
setattr(settings, key, value)