diff options
author | Xtreak <tir.karthi@gmail.com> | 2019-02-25 00:24:49 +0530 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-02-24 18:54:49 +0000 |
commit | a875ea58b29fbf510f9790ae1653eeaa47dc0de8 (patch) | |
tree | 076c625afd240521c200df9b98485846f32687a4 /Lib/unittest/test/testmock/testpatch.py | |
parent | aeca373b339e0ea9739536ce6b43bd90f3b89873 (diff) | |
download | cpython-git-a875ea58b29fbf510f9790ae1653eeaa47dc0de8.tar.gz |
bpo-35512: Resolve string target to patch.dict decorator during function call GH#12000
* Resolve string target to patch.dict during function call
* Add NEWS entry
* Remove unneeded call
* Restore original value for support.target and refactor assertions
* Add extra assertion to verify unpatched dict
Diffstat (limited to 'Lib/unittest/test/testmock/testpatch.py')
-rw-r--r-- | Lib/unittest/test/testmock/testpatch.py | 17 |
1 files changed, 17 insertions, 0 deletions
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 |