mirror of
https://github.com/django/django.git
synced 2025-04-25 17:54:37 +00:00
Fixed #27032 -- Prevented setup_test_environment() from being called twice.
This commit is contained in:
parent
a7863c78b7
commit
e7fb724cd2
@ -99,6 +99,13 @@ def setup_test_environment():
|
|||||||
Perform global pre-test setup, such as installing the instrumented template
|
Perform global pre-test setup, such as installing the instrumented template
|
||||||
renderer and setting the email backend to the locmem email backend.
|
renderer and setting the email backend to the locmem email backend.
|
||||||
"""
|
"""
|
||||||
|
if hasattr(Template, '_original_render'):
|
||||||
|
# Executing this function twice would overwrite the saved values.
|
||||||
|
raise RuntimeError(
|
||||||
|
"setup_test_environment() was already called and can't be called "
|
||||||
|
"again without first calling teardown_test_environment()."
|
||||||
|
)
|
||||||
|
|
||||||
Template._original_render = Template._render
|
Template._original_render = Template._render
|
||||||
Template._render = instrumented_test_render
|
Template._render = instrumented_test_render
|
||||||
|
|
||||||
|
@ -364,6 +364,11 @@ Miscellaneous
|
|||||||
:meth:`~django.db.models.fields.related.RelatedManager.set` now
|
:meth:`~django.db.models.fields.related.RelatedManager.set` now
|
||||||
clear the ``prefetch_related()`` cache.
|
clear the ``prefetch_related()`` cache.
|
||||||
|
|
||||||
|
* To prevent possible loss of saved settings,
|
||||||
|
:func:`~django.test.utils.setup_test_environment` now raises an exception if
|
||||||
|
called a second time before calling
|
||||||
|
:func:`~django.test.utils.teardown_test_environment`.
|
||||||
|
|
||||||
.. _deprecated-features-1.11:
|
.. _deprecated-features-1.11:
|
||||||
|
|
||||||
Features deprecated in 1.11
|
Features deprecated in 1.11
|
||||||
|
@ -20,6 +20,7 @@ from django.test import (
|
|||||||
from django.test.html import HTMLParseError, parse_html
|
from django.test.html import HTMLParseError, parse_html
|
||||||
from django.test.utils import (
|
from django.test.utils import (
|
||||||
CaptureQueriesContext, isolate_apps, override_settings,
|
CaptureQueriesContext, isolate_apps, override_settings,
|
||||||
|
setup_test_environment,
|
||||||
)
|
)
|
||||||
from django.urls import NoReverseMatch, reverse
|
from django.urls import NoReverseMatch, reverse
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
@ -864,6 +865,13 @@ class SecondUrls:
|
|||||||
urlpatterns = [url(r'second/$', empty_response, name='second')]
|
urlpatterns = [url(r'second/$', empty_response, name='second')]
|
||||||
|
|
||||||
|
|
||||||
|
class SetupTestEnvironmentTests(SimpleTestCase):
|
||||||
|
|
||||||
|
def test_setup_test_environment_calling_more_than_once(self):
|
||||||
|
with self.assertRaisesMessage(RuntimeError, "setup_test_environment() was already called"):
|
||||||
|
setup_test_environment()
|
||||||
|
|
||||||
|
|
||||||
class OverrideSettingsTests(SimpleTestCase):
|
class OverrideSettingsTests(SimpleTestCase):
|
||||||
|
|
||||||
# #21518 -- If neither override_settings nor a setting_changed receiver
|
# #21518 -- If neither override_settings nor a setting_changed receiver
|
||||||
|
Loading…
x
Reference in New Issue
Block a user