diff options
author | Xtreak <tir.karthi@gmail.com> | 2019-05-28 07:07:39 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-28 07:07:38 (GMT) |
commit | 436c2b0d67da68465e709a96daac7340af3a5238 (patch) | |
tree | 771d8d39bd772a7aa72640670e247b7e5bb14f6b /Lib/unittest/test/testmock | |
parent | 71dc7c5fbd856df83202f39c1f41ccd07c6eceb7 (diff) | |
download | cpython-436c2b0d67da68465e709a96daac7340af3a5238.zip cpython-436c2b0d67da68465e709a96daac7340af3a5238.tar.gz cpython-436c2b0d67da68465e709a96daac7340af3a5238.tar.bz2 |
bpo-36996: Handle async functions when mock.patch is used as a decorator (GH-13562)
Return a coroutine while patching async functions with a decorator.
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
https://bugs.python.org/issue36996
Diffstat (limited to 'Lib/unittest/test/testmock')
-rw-r--r-- | Lib/unittest/test/testmock/testasync.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py index 0519d59..ccea4fe 100644 --- a/Lib/unittest/test/testmock/testasync.py +++ b/Lib/unittest/test/testmock/testasync.py @@ -66,6 +66,14 @@ class AsyncPatchDecoratorTest(unittest.TestCase): test_async() + def test_async_def_patch(self): + @patch(f"{__name__}.async_func", AsyncMock()) + async def test_async(): + self.assertIsInstance(async_func, AsyncMock) + + asyncio.run(test_async()) + self.assertTrue(inspect.iscoroutinefunction(async_func)) + class AsyncPatchCMTest(unittest.TestCase): def test_is_async_function_cm(self): @@ -91,6 +99,14 @@ class AsyncPatchCMTest(unittest.TestCase): test_async() + def test_async_def_cm(self): + async def test_async(): + with patch(f"{__name__}.async_func", AsyncMock()): + self.assertIsInstance(async_func, AsyncMock) + self.assertTrue(inspect.iscoroutinefunction(async_func)) + + asyncio.run(test_async()) + class AsyncMockTest(unittest.TestCase): def test_iscoroutinefunction_default(self): |