[TIP] Mock and multiprocessing on Windows
stefan at sofa-rockers.org
Tue Sep 25 01:23:31 PDT 2012
[tl;dr] Below is a snippet that works on Linux/Mac but fails on Windows. Is there a way to fix it?
The example below fails on Windows, because it uses spawn() to start subprocesses. The python
state is being pickled and sent to the new process. However, pickling mock objects doesn’t
work, so the example fails.
Is there another way to mock something in a subprocess on Windows?
Below is a minimal example that prints
on Mac/Linux and:
with mock.patch('sub.spam') as spam_mock:
spam_mock.return_value = 'eggs'
p = multiprocessing.Process(target=sub.main)
if __name__ == '__main__':
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2772 bytes
Desc: not available
More information about the testing-in-python