New feature - Define a variable TESTS in settings

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

New feature - Define a variable TESTS in settings

אורי
Hi,

I think it might be useful to define a variable (such as TESTS) in settings, which will only be True when running tests, and then Django will know we are running tests and act accordingly, for example save files in a different directory (such as TESTS_MEDIA_ROOT) and not in the default MEDIA_ROOT directory, and delete them after all the tests end. And other actions which should run only in tests or only not in tests.

If such a variable is defined, its default value should be of course False.


Please see my recent comment on this ticket:
https://code.djangoproject.com/ticket/23251

I already defined different settings files in Speedy Net, and set set django_settings.TESTS to True only in tests. Until recently it was possible to run tests with other settings such as development, when running tests locally, but now it's deliberately disabled (with two asserts in speedy/core/base/test/models.py) because I don't want tests to run with the production (or development) MEDIA_ROOT settings.

Also notice, I used django_settings.TESTS_MEDIA_ROOT instead of django_settings.MEDIA_ROOT in tearDownClass in the above file, to prevent deleting the production MEDIA_ROOT directory by accident if the tests will still run in production (although it can't because of the asserts above).

I will appreciate your feedback or comments.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeFxQWQqiYxGSRm3jSUUzYvpO52Cc9B0MXtq0XfVyF6AHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: New feature - Define a variable TESTS in settings

René Fleschenberg
Hi,

I think it is better to do what Josh mentioned in
https://code.djangoproject.com/ticket/30605#comment:2.

To elaborate on how this looks in pratice:

Write a file called ``settings_test.py`` or such, containing something
like this:

```
from .settings import *

DEFAULT_FILE_STORAGE = 'inmemorystorage.InMemoryStorage'

# More test-specific settings here
```

And run your tests with this settings module (using ``manage.py
--settings settings_test test`` or by setting the
``DJANGO_SETTINGS_MODULE`` env var).

René

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d60d44e9-06f1-d883-f041-b1e9c68f2245%40fleschenberg.net.
For more options, visit https://groups.google.com/d/optout.