mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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
This commit is contained in:
parent
aeca373b33
commit
a875ea58b2
4 changed files with 25 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue