#23251: Use a temporary folder to store uploaded files during tests
-------------------------------------+------------------------------------
Reporter: Shai Berger | Owner: (none)
Type: Bug | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: file storage upload | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by bcail):
* cc: bcail (added)
Comment:
Here's a small patch that sets the default storage to a temporary
directory:
{{{
diff --git a/django/test/utils.py b/django/test/utils.py
index ddb85127dc..2564e745ca 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -1,9 +1,11 @@
import collections
+import copy
import gc
import logging
import os
import re
import sys
+import tempfile
import time
import warnings
from contextlib import contextmanager
@@ -149,6 +151,10 @@ def setup_test_environment(debug=None):
saved_data.template_render = Template._render
Template._render = instrumented_test_render
+ saved_data.storages = copy.deepcopy(settings.STORAGES)
+ settings.STORAGES["default"]["BACKEND"] =
"django.core.files.storage.FileSystemStorage"
+ settings.STORAGES["default"]["OPTIONS"] = {"location":
tempfile.mkdtemp()}
+
mail.outbox = []
deactivate()
@@ -165,6 +171,7 @@ def teardown_test_environment():
settings.DEBUG = saved_data.debug
settings.EMAIL_BACKEND = saved_data.email_backend
Template._render = saved_data.template_render
+ settings.STORAGES = saved_data.storages
del _TestState.saved_data
del mail.outbox
}}}
Note: it doesn't currently allow for users to opt out of that behavior.
Also, it makes some of the tests fail when they expect the settings to be
different.
--
Ticket URL: <https://code.djangoproject.com/ticket/23251#comment:25>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d8ed3e8cc-028ec8cd-8457-4c1b-8366-a3801e731772-000000%40eu-central-1.amazonses.com.