﻿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
27032	"Calling setup_test_environment() ""twice"" deletes pre-setup state"	Chris Jerdonek	Chris Jerdonek	"Currently, if `django.test.utils.setup_test_environment()` is called twice before calling `teardown_test_environment()`, then the saved, pre-setup state is lost, causing a subsequent call to `teardown_test_environment()` not to work as it should. This is because `setup_test_environment()` saves the current state to a single backup location that gets overwritten each time the function is called.  See [https://github.com/django/django/blob/6fe391d437cdf9866c34e30b2f3831e9d12e637b/django/test/utils.py#L97 here] for a link to the body of the function.

This behavior is somewhat subtle and could lead to hard-to-trackdown (or unnoticed) bugs.

I propose raising an exception if `setup_test_environment()` is called twice. This would have averted [https://code.djangoproject.com/ticket/27012 this issue], for example.

I started a pull request to do this [https://github.com/django/django/pull/7032 here]. However, I will create a new PR with an updated patch after this ticket is created (at which point I will have a ticket number to reference)."	Cleanup/optimization	closed	Testing framework	dev	Normal	fixed			Accepted	1	0	0	0	0	0
