mock.patch and multiprocessing
问题 I'm struggling to use mock.patch in a multiprocessing environment while without multiprocessing mock.patch works fine. Filename: test_mp.py import multiprocessing import mock def inner(): return sub() def sub(): return "abc" def test_local(): assert inner()=="abc" def test_mp(): with multiprocessing.Pool() as pool: assert pool.apply(inner,args=[])=='abc' def test_mock(): with mock.patch('test_mp.sub', return_value='xxx') as xx: assert inner()=="xxx" xx.assert_called_once() def test_mp_mock():