summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/unittest/mock.py1
-rw-r--r--Lib/unittest/test/testmock/testpatch.py7
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index fac4535..055fbb3 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1730,6 +1730,7 @@ class _patch_dict(object):
def __enter__(self):
"""Patch the dict."""
self._patch_dict()
+ return self.in_dict
def _patch_dict(self):
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py
index 3295c5b..27914a9 100644
--- a/Lib/unittest/test/testmock/testpatch.py
+++ b/Lib/unittest/test/testmock/testpatch.py
@@ -619,6 +619,13 @@ class PatchTest(unittest.TestCase):
self.assertEqual(foo.values, original)
+ def test_patch_dict_as_context_manager(self):
+ foo = {'a': 'b'}
+ with patch.dict(foo, a='c') as patched:
+ self.assertEqual(patched, {'a': 'c'})
+ self.assertEqual(foo, {'a': 'b'})
+
+
def test_name_preserved(self):
foo = {}