Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,22 @@ that proxy attribute access, like the `django settings object
<https://web.archive.org/web/20200603181648/http://www.voidspace.org.uk/python/weblog/arch_d7_2010_12_04.shtml#e1198>`_.


Patching with multiprocessing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:func:`patch` modifies objects in the current process's memory. Patches are
not inherited by child processes created with the ``"forkserver"`` or
``"spawn"`` :mod:`multiprocessing` start methods.

To apply patches in child processes, use a pool initializer::

def init_worker():
mock.patch.object(MyClass, "method", return_value=42).start()

with multiprocessing.Pool(initializer=init_worker) as pool:
pool.map(my_func, range(5))


MagicMock and magic method support
----------------------------------

Expand Down
Loading