Commit 93440075 authored by Aymeric Augustin's avatar Aymeric Augustin Committed by Aymeric Augustin
Browse files

Guaranteed removal of temporary files during tests.

Dropped the DJANGO_TEST_TEMP_DIR environment variable.

Before this change, proper removal depended on the developer passing
dir=os.environ['DJANGO_TEST_TMP_DIR'] to tempfile functions.
parent e83aba0e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import shutil
import socket
import subprocess
import sys
import tempfile
import unittest

import django
@@ -27,7 +28,7 @@ from django.utils._os import npath, upath
from django.utils.encoding import force_text
from django.utils.six import StringIO

test_dir = os.path.realpath(os.path.join(os.environ['DJANGO_TEST_TEMP_DIR'], 'test_project'))
test_dir = os.path.realpath(os.path.join(tempfile.gettempdir(), 'test_project'))
if not os.path.exists(test_dir):
    os.mkdir(test_dir)
    open(os.path.join(test_dir, '__init__.py'), 'w').close()
+1 −1
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ class OldSubscriberAdmin(admin.ModelAdmin):
    actions = None


temp_storage = FileSystemStorage(tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR']))
temp_storage = FileSystemStorage(tempfile.mkdtemp())
UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')


+1 −1
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ class EmptyModel(models.Model):
        return "Primary key = %s" % self.id


temp_storage = FileSystemStorage(tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR']))
temp_storage = FileSystemStorage(tempfile.mkdtemp())
UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')


+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ Storing files according to a custom storage system
and where files should be stored.
"""

import os
import random
import tempfile

@@ -26,7 +25,7 @@ class OldStyleFSStorage(FileSystemStorage):
        return super(OldStyleFSStorage, self).save(name, content)


temp_storage_location = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
temp_storage_location = tempfile.mkdtemp()
temp_storage = FileSystemStorage(location=temp_storage_location)


+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ from . import uploadhandler
from .models import FileModel

UNICODE_FILENAME = 'test-0123456789_中文_Orléans.jpg'
MEDIA_ROOT = sys_tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
MEDIA_ROOT = sys_tempfile.mkdtemp()
UPLOAD_TO = os.path.join(MEDIA_ROOT, 'test_upload')


Loading