Skip to content
Prev Previous commit
bpo-32299: unittest.patch.dict now returns patched dict when used as …
…context manager
  • Loading branch information
taiye-ts committed Dec 29, 2017
commit f00a26671604446eaef3a95885ac38568a906f01
5 changes: 3 additions & 2 deletions Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,7 @@ patch.dict

:func:`patch.dict` can be used as a context manager, decorator or class
decorator. When used as a class decorator :func:`patch.dict` honours
``patch.TEST_PREFIX`` for choosing which methods to wrap. When used as a
context manager it returns patched *in_dict*.
``patch.TEST_PREFIX`` for choosing which methods to wrap.

:func:`patch.dict` can be used to add members to a dictionary, or simply let a test
change a dictionary, and ensure the dictionary is restored when the test
Expand Down Expand Up @@ -1333,6 +1332,8 @@ magic methods :meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and
>>> assert thing['one'] == 1
>>> assert list(thing) == ['one']

:func:`patch.dict` returns a patched dictionary when used as context manager.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be moved after the paragraph that starts with ":func:`patch.dict` can be used as a context manager, [...]".

Also, add a versionchanged marker after that paragraph:

.. versionchanged:: 3.7
   :func:`patch.dict` now returns the patched dictionary when it used as a context manager.

(Feel free to use any wording you want, I just gave an example.)



patch.multiple
~~~~~~~~~~~~~~
Expand Down