Skip to content

Commit

Permalink
[2.1.x] Fixed #29226 -- Doc'd modify_settings() ordering consideratio…
Browse files Browse the repository at this point in the history
…ns for Python < 3.6.

Backport of 08f788b from master
  • Loading branch information
benjaoming authored and timgraham committed Aug 25, 2018
1 parent 22fa926 commit fb9c1f4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/topics/testing/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,23 @@ The decorator can also be applied to test case classes::
decorator. For a given class, :func:`~django.test.modify_settings` is
always applied after :func:`~django.test.override_settings`.

.. admonition:: Considerations with Python 3.5

If using Python 3.5 (or older, if using an older version of Django), avoid
mixing ``remove`` with ``append`` and ``prepend`` in
:func:`~django.test.modify_settings`. In some cases it matters whether a
value is first added and then removed or vice versa, and dictionary key
order isn't preserved until Python 3.6. Instead, apply the decorator twice
to guarantee the order of operations. For example, to ensure that
``SessionMiddleware`` appears first in ``MIDDLEWARE``::

@modify_settings(MIDDLEWARE={
'remove': ['django.contrib.sessions.middleware.SessionMiddleware'],
)
@modify_settings(MIDDLEWARE={
'prepend': ['django.contrib.sessions.middleware.SessionMiddleware'],
})

.. warning::

The settings file contains some settings that are only consulted during
Expand Down

0 comments on commit fb9c1f4

Please sign in to comment.