Thursday, September 20, 2018

Re: DEFAULT_FILE_STORAGE and tests

On Thu, Sep 20, 2018 at 3:25 PM sandro dentella <sandro.dentella@gmail.com> wrote:


from django.conf import settings
from django.test.runner import DiscoverRunner


class GeneraliDiscoverRunner(DiscoverRunner):
   
def __init__(self, *args, **kwargs):
        settings
.DEFAULT_FILE_STORAGE = 'web.storage.TestStorage'
       
super().__init__(*args, **kwargs)

It seems that this changes the Storage in all situations apart from the fields declared in the models via the storage=ThumbnailStorage. I guess when model are read the settings from the runner has not yet been set. Is there a way to set the Storage in due time?

Not really sure, but you can use override_settings from django.test.utils as

from django.test.utils import override_settings
@override_settings(DEFAULT_FILE_STORAGE='web.storage.TestStorage')
class GeneraliDiscoverRunner(DiscoverRunner):
    pass

(override_settings does a lot of other things)

or use a custom DJANGO_SETTINGS_MODULE

-- 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABgH4JsQ93KtvRqs0F00hoLTp7_M%2BAqrLFn65iTtS%3DeBJ9YQvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment