Run django.setup() after coverage.start() in tests to fix coverage report.

Fixes #1007.
This commit is contained in:
Alex Wilson 2016-06-20 22:49:45 -04:00 committed by Tim Abbott
parent 2640cc44c7
commit f68a392250
1 changed files with 4 additions and 1 deletions

View File

@ -25,7 +25,6 @@ if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
# "-u" uses unbuffered IO, which is important when wrapping it in subprocess
os.environ['PYTHONUNBUFFERED'] = 'y'
django.setup()
parser = optparse.OptionParser()
parser.add_option('--nonfatal-errors', action="store_false", default=True,
@ -63,6 +62,10 @@ if __name__ == "__main__":
prof = cProfile.Profile()
prof.enable()
# setup() needs to be called after coverage is started to get proper coverage reports of model
# files, since part of setup is importing the models for all applications in INSTALLED_APPS.
django.setup()
subprocess.call(os.path.join(TOOLS_DIR, 'setup', 'generate-fixtures'))
TestRunner = get_runner(settings)