Opened 5 years ago

Closed 5 years ago

#30605 closed New feature (wontfix)

Define a variable TESTS in settings

Reported by: אורי Owned by: nobody
Component: Uncategorized Version:
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

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 should be of course False.

Change History (3)

comment:1 by אורי, 5 years ago

Summary: Define a a variable TESTS in settingsDefine a variable TESTS in settings

comment:2 by Josh Smeaton, 5 years ago

How I've traditionally handled this is to define a completely new settings module: tests.py.

It inherits all values from the production settings module, and then overrides everything else it needs to.

Django forcing a setting based on the context it is running in isn't such a good idea - especially since it'd have to do so after the settings have already been loaded.

Steps:

  1. Run a management command called "test"
  2. Run django.setup()
  3. Settings are configured
  4. The test command is run

It's already "too late" at this stage to set a global setting.

comment:3 by Carlton Gibson, 5 years ago

Resolution: wontfix
Status: newclosed

I think Josh's suggestion is pretty standard here. A change here would need to go via the DevelopersMailingList, but I (strongly) suspect there would be little support for adding a setting.

Note: See TracTickets for help on using tickets.
Back to Top