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.

Author asvetlov
Recipients Liran Nuna, asvetlov, yselivanov
Date 2019-05-29.14:29:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559140174.84.0.518350300306.issue33918@roundup.psfhosted.org>
In-reply-to
Content
decimal was changed from threading.local to contextvar usage.
The module is "safe" not only for asyncio but for threading, trio etc.

unittest.mock doesn't use explicit context all for patching.
It changes global interpreter-wide objects instead.

So, mock.patch fails not only if two async tasks are executed in parallel but two threads also.

I doubt if thread-local (or contextvar) can be applied to mock because it changes the current behavior -- but this is a different story.

*Any* library that needs to modify a global state, e.g. your MyLogger.enabled can use contextvars for handling it.

Say again, contextvars is not for asyncio-only but a generic instrument for handling context-aware variables.

I'm going to close the issue.
History
Date User Action Args
2019-05-29 14:29:34asvetlovsetrecipients: + asvetlov, yselivanov, Liran Nuna
2019-05-29 14:29:34asvetlovsetmessageid: <1559140174.84.0.518350300306.issue33918@roundup.psfhosted.org>
2019-05-29 14:29:34asvetlovlinkissue33918 messages
2019-05-29 14:29:34asvetlovcreate