This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: incompatible: unittest.mock.sentinel and
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: duplicate
Dependencies: Superseder: Sentinels identity lost when pickled (unittest.mock)
View: 20804
Assigned To: Nosy List: davin, jason.curtis
Priority: normal Keywords:

Created on 2017-01-10 19:22 by jason.curtis, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg285146 - (view) Author: Jason Curtis (jason.curtis) * Date: 2017-01-10 19:22
When a sentinel object from unittest.mock.sentinel is passed through a, I expect it to still be comparable. 

As a user, I'd like to be able to write a unit test using sentinels on my unparallelized code, and then see that the test still passes after I parallelize the code using multiprocessing, so that I can make use of sentinels in regression testing.

from unittest import mock
import multiprocessing

def identity(x):
    return x

with multiprocessing.Pool() as pool:
    multiprocessed = list(, []))

assert identity( ==  # Passes
assert multiprocessed[0] ==  # Fails
msg285149 - (view) Author: Davin Potts (davin) * (Python committer) Date: 2017-01-10 19:41
This arises from the behavior of pickle (which is used by default in multiprocessing to serialize objects sent to / received from other processes in data exchanges), as seen with Python 3.6:

>>> import pickle
>>> x = pickle.dumps(
>>> x
>>> pickle.loads(x)
>>> pickle.loads(x) ==
msg285151 - (view) Author: Davin Potts (davin) * (Python committer) Date: 2017-01-10 19:49
I think this should be regarded as a duplicate of issue20804 though discussion in issue14577 is also related/relevant.
msg285174 - (view) Author: Jason Curtis (jason.curtis) * Date: 2017-01-11 00:56
sounds right; closing as a duplicate of issue20804
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73415
2017-01-11 00:56:45jason.curtissetstatus: open -> closed
resolution: duplicate
messages: + msg285174
2017-01-10 19:49:59davinsetsuperseder: Sentinels identity lost when pickled (unittest.mock)
messages: + msg285151
2017-01-10 19:41:17davinsetnosy: + davin
messages: + msg285149
2017-01-10 19:22:09jason.curtiscreate