From d6be404e565fd04538ebc4771aa98422cc03fd2e Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 4 Jun 2015 18:35:18 +0200 Subject: [PATCH] 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. --- tests/runtests.py | 16 +++++++--------- 1 file 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)