summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Christopher Henry <k@severian.com>2013-09-19 17:02:49 -0400
committerTim Graham <timograham@gmail.com>2013-10-02 19:13:20 -0400
commit02c7dbd2559de4fa09cf6c644a2434e440230c0d (patch)
tree836e922c6aacf7c70810536c61d8597f1dbcd025
parent06b149e220f98cd643a4445db1b5719daac0d56f (diff)
[1.6.x] Fixed #21122 -- Improved clean up of test temp directory on Windows
- Fixed test that didn't close the files it opened - Caught and handled exception when temp directory cannot be removed Backport of 978e1351a6 of master
-rw-r--r--tests/files/tests.py3
-rwxr-xr-xtests/runtests.py23
2 files changed, 19 insertions, 7 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 79d5e97164..daf5a30e9d 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -175,3 +175,6 @@ class FileMoveSafeTests(unittest.TestCase):
# should allow it and continue on if allow_overwrite is True
self.assertIsNone(file_move_safe(self.file_a, self.file_b, allow_overwrite=True))
+
+ os.close(handle_a)
+ os.close(handle_b)
diff --git a/tests/runtests.py b/tests/runtests.py
index 0d8df30bf7..90f3038b3e 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -146,8 +146,8 @@ def setup(verbosity, test_labels):
module_found_in_labels = True
else:
match = lambda label: (
- module_label == label or # exact match
- module_label.startswith(label + '.') # ancestor match
+ module_label == label or # exact match
+ module_label.startswith(label + '.') # ancestor match
)
module_found_in_labels = any(match(l) for l in test_labels_set)
@@ -162,17 +162,24 @@ def setup(verbosity, test_labels):
return state
+
def teardown(state):
from django.conf import settings
- # Removing the temporary TEMP_DIR. 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(TEMP_DIR))
+
+ try:
+ # Removing the temporary TEMP_DIR. 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(TEMP_DIR))
+ except OSError:
+ print('Failed to remove temp directory: %s' % TEMP_DIR)
+
# Restore the old settings.
for key, value in state.items():
setattr(settings, key, value)
+
def django_tests(verbosity, interactive, failfast, test_labels):
from django.conf import settings
state = setup(verbosity, test_labels)
@@ -253,6 +260,7 @@ def bisect_tests(bisection_label, options, test_labels):
print("***** Source of error: %s" % test_labels[0])
teardown(state)
+
def paired_tests(paired_test, options, test_labels):
state = setup(int(options.verbosity), test_labels)
@@ -288,6 +296,7 @@ def paired_tests(paired_test, options, test_labels):
print('***** No problem pair found')
teardown(state)
+
if __name__ == "__main__":
from optparse import OptionParser
usage = "%prog [options] [module module module ...]"