classification
Title: unittest.mock.patch.dict.__enter__ should return the dict
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Allen Li, cheryl.sabella, michael.foord, rbcollins, xtreak
Priority: normal Keywords: patch

Created on 2017-12-13 07:08 by Allen Li, last changed 2019-05-28 12:59 by cheryl.sabella. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4834 closed Vadim Tsander, 2017-12-13 09:59
PR 11062 merged mariocj89, 2018-12-10 09:18
Messages (4)
msg308188 - (view) Author: Allen Li (Allen Li) Date: 2017-12-13 07:08
mock.patch.dict.__enter__ should return the patched dict/mapping object.

Currently it returns nothing (None).

This would make setting up fixtures more convenient:

 with mock.patch.dict(some.thing):
   some.thing['foo'] = 'bar'

 with mock.patch.dict(some.thing) as x:
   x['foo'] = 'bar'
msg310489 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2018-01-23 09:35
This seems like a reasonable feature request.
msg343772 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-28 12:53
New changeset 04530812e90e45a37ed84e83505d63db7edc1262 by Cheryl Sabella (Mario Corchero) in branch 'master':
bpo-32299: Return patched dict when using patch.dict as a context manager (GH-11062)
https://github.com/python/cpython/commit/04530812e90e45a37ed84e83505d63db7edc1262
msg343775 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-28 12:59
@Allen Li, thank you for the report.  And thank you, @Vadim Tsander for the original pull request and @mariocj89 for reviving this.  Also, thank you @eric.araujo for the review and approval.  This has been merged!
History
Date User Action Args
2019-05-28 12:59:19cheryl.sabellasetstatus: open -> closed
resolution: fixed
messages: + msg343775

stage: patch review -> resolved
2019-05-28 12:53:35cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg343772
2019-04-12 23:28:31cheryl.sabellasetnosy: + xtreak

versions: + Python 3.8, - Python 3.7
2018-12-10 09:18:19mariocj89setpull_requests: + pull_request10296
2018-01-23 09:35:32michael.foordsetmessages: + msg310489
2018-01-23 08:09:40berker.peksagsetnosy: + rbcollins, michael.foord

versions: - Python 3.6, Python 3.8
2017-12-13 09:59:16Vadim Tsandersetkeywords: + patch
stage: patch review
pull_requests: + pull_request4726
2017-12-13 07:08:31Allen Lisettype: enhancement
2017-12-13 07:08:20Allen Licreate