Tuesday, September 25, 2018

Re: DEFAULT_FILE_STORAGE and tests

already tried:

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

?

although I'm not sure that settings can be changed at runtime by that.

other options:
- use a custom settings module (already suggested)
- try to make the change in the setUp method of your TestCase subclass.

additional info about how you're trying to do that would be helpful.

L

Il giorno giovedì 20 settembre 2018 15:59:11 UTC+2, sandro dentella ha scritto:

Hi Raffaele,

On Thu, Sep 20, 2018 at 03:36:11PM +0200, Raffaele Salmaso wrote:
>    On Thu, Sep 20, 2018 at 3:25 PM sandro dentella
>    <[1]sandro....@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

really I've already tried it as well, but it happens the same: it
doesn't work for the Storage declared in the models.

I'd need to set the settings *before* the models are read. It seems
that the runner is instantiated too late!


sandro

--
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/ee87371e-f1b4-4ac1-b39b-0ac32fb8f5f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment