diff options
Diffstat (limited to 'Lib/unittest/test')
| -rw-r--r-- | Lib/unittest/test/testmock/support.py | 3 | ||||
| -rw-r--r-- | Lib/unittest/test/testmock/testpatch.py | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/support.py b/Lib/unittest/test/testmock/support.py index c7ad20b806..f146be244e 100644 --- a/Lib/unittest/test/testmock/support.py +++ b/Lib/unittest/test/testmock/support.py @@ -1,3 +1,6 @@ +target = {'foo': 'FOO'} + + def is_instance(obj, klass): """Version of is_instance that doesn't access __class__""" return issubclass(type(obj), klass) diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py index f05225730d..c484adb605 100644 --- a/Lib/unittest/test/testmock/testpatch.py +++ b/Lib/unittest/test/testmock/testpatch.py @@ -664,6 +664,23 @@ class PatchTest(unittest.TestCase): test() + def test_patch_dict_decorator_resolution(self): + # bpo-35512: Ensure that patch with a string target resolves to + # the new dictionary during function call + original = support.target.copy() + + @patch.dict('unittest.test.testmock.support.target', {'bar': 'BAR'}) + def test(): + self.assertEqual(support.target, {'foo': 'BAZ', 'bar': 'BAR'}) + + try: + support.target = {'foo': 'BAZ'} + test() + self.assertEqual(support.target, {'foo': 'BAZ'}) + finally: + support.target = original + + def test_patch_descriptor(self): # would be some effort to fix this - we could special case the # builtin descriptors: classmethod, property, staticmethod |
