﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26576	django.conf and test discovery issues with Python 3.5	Lex Berezhny	nobody	"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 [https://github.com/django/django/blob/master/django/test/runner.py#L466 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:

 {{{
#!python
>>> 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."	Bug	closed	Testing framework	1.9	Normal	duplicate			Unreviewed	0	0	0	0	0	0
