[3.11] gh-98086: Now `patch.dict` can decorate async functions (GH-98095) (#99365)

gh-98086: Now ``patch.dict`` can decorate async functions (GH-98095)
(cherry picked from commit 67b4d2772c)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2022-11-19 02:10:42 -08:00 committed by GitHub
parent 369cb3e66a
commit 7e742379af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View file

@ -149,6 +149,23 @@ class AsyncPatchCMTest(unittest.TestCase):
run(test_async())
def test_patch_dict_async_def(self):
foo = {'a': 'a'}
@patch.dict(foo, {'a': 'b'})
async def test_async():
self.assertEqual(foo['a'], 'b')
self.assertTrue(iscoroutinefunction(test_async))
run(test_async())
def test_patch_dict_async_def_context(self):
foo = {'a': 'a'}
async def test_async():
with patch.dict(foo, {'a': 'b'}):
self.assertEqual(foo['a'], 'b')
run(test_async())
class AsyncMockTest(unittest.TestCase):
def test_iscoroutinefunction_default(self):