diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-20 08:06:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 21:36:57 +0530 |
commit | 88b101ff52010f795b34e3afc04c0e934d662d82 (patch) | |
tree | 25582945bc12f7ae3871f467386c4f3d8e408da9 /Lib/unittest/test/testmock/testasync.py | |
parent | 42b7b2179e27f6df110a1b528fc948784e497265 (diff) | |
download | cpython-git-88b101ff52010f795b34e3afc04c0e934d662d82.tar.gz |
[3.10] gh-98086: Now ``patch.dict`` can decorate async functions (GH-98095) (GH-99366)
gh-98086: Now ``patch.dict`` can decorate async functions (GH-98095)
(cherry picked from commit 67b4d2772c5124b908f8ed9b13166a79bbeb88d2)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Chris Withers <chris@withers.org>
Diffstat (limited to 'Lib/unittest/test/testmock/testasync.py')
-rw-r--r-- | Lib/unittest/test/testmock/testasync.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py index e1866a3492..22228b47de 100644 --- a/Lib/unittest/test/testmock/testasync.py +++ b/Lib/unittest/test/testmock/testasync.py @@ -146,6 +146,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): |