From 67b4d2772c5124b908f8ed9b13166a79bbeb88d2 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 11 Nov 2022 11:04:30 +0300 Subject: gh-98086: Now ``patch.dict`` can decorate async functions (#98095) --- Lib/test/test_unittest/testmock/testasync.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Lib/test/test_unittest/testmock/testasync.py') diff --git a/Lib/test/test_unittest/testmock/testasync.py b/Lib/test/test_unittest/testmock/testasync.py index 1bab671acde..e05a22861d4 100644 --- a/Lib/test/test_unittest/testmock/testasync.py +++ b/Lib/test/test_unittest/testmock/testasync.py @@ -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): -- cgit v1.2.3