Opened 8 years ago

Closed 8 years ago

#26576 closed Bug (duplicate)

django.conf and test discovery issues with Python 3.5

Reported by: Lex Berezhny Owned by: nobody
Component: Testing framework Version: 1.9
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

There appears to be an issue between django loaded app settings and the same settings being loaded again by the test discover code.

I should first mention how my settings are laid out:

/project/settings/__init__.py <-- imports .local or .production
/project/settings/local.py
/project/settings/production.py
/project/apps <-- different apps

__init__.py is something like from .local import * and is not checked into version control.
manage.py has DJANGO_SETTINGS_MODULE=project.settings.

This setup has worked just fine up until upgrade to Python 3.5 (from 3.4).

The issue now, when running ./manage.py test project is that the settings get loaded twice:

  1. Django loads the settings first and proceeds to fill in all of the default/missing settings values.
  2. After Django finishes loading the test discovery code runs, if the settings directory is in the path of the discover search then the __init__.py gets loaded again and ends up resetting the settings+default values loaded in step 1.

For example, stepping through the debugger on line 466 in django/test/runner.py and printing the before (repl line 1 below) and after (repl line 2) values of default connection settings produces the following results:

>>> connections['default'].settings_dict['TEST']
{'MIRROR': None, 'NAME': None, 'CHARSET': None, 'SERIALIZE': False, 'COLLATION': None}
>>> connections['default'].settings_dict['TEST']
{'SERIALIZE': False}

It seems that something has changed in Python 3.5 that causes Python to realize that the same module is being imported again and to overwrite the previous import erasing the defaults set by Django.

If instead of ./manage.py test project I run ./manage.py test project.apps then all of the tests work fine.

Possible solutions:

  1. Provide some kind of useful error explaining why this is happening. - or -
  2. Prevent the settings from getting reset when test discovery finds and loads the settings module.

Change History (1)

comment:1 by Claude Paroz, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #26570.

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