diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-06-30 18:02:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-30 18:02:15 (GMT) |
commit | 47f23b2d8a14a2f182375c840776eadfc371c726 (patch) | |
tree | 76ead06fbb8909c527a9438d7069c795b71ce87f /Lib/test | |
parent | d915ed297804041c822a595c0f44e52a4c385302 (diff) | |
download | cpython-47f23b2d8a14a2f182375c840776eadfc371c726.zip cpython-47f23b2d8a14a2f182375c840776eadfc371c726.tar.gz cpython-47f23b2d8a14a2f182375c840776eadfc371c726.tar.bz2 |
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-94050) (GH-94461)
The inspect version was not working with unittest.mock.AsyncMock.
The fix introduces special-casing of AsyncMock in
`inspect.iscoroutinefunction` equivalent to the one
performed in `asyncio.iscoroutinefunction`.
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
(cherry picked from commit 4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc)
Co-authored-by: Mehdi ABAAKOUK <sileht@sileht.net>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 1 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 0007b44..05a822b 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1723,6 +1723,7 @@ class BaseTaskTests: self.assertTrue(asyncio.iscoroutinefunction(fn2)) self.assertFalse(asyncio.iscoroutinefunction(mock.Mock())) + self.assertTrue(asyncio.iscoroutinefunction(mock.AsyncMock())) def test_yield_vs_yield_from(self): fut = self.new_future(self.loop) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 28e4f5b..eaefe94 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -188,6 +188,10 @@ class TestPredicates(IsTestBase): gen_coroutine_function_example)))) self.assertTrue(inspect.isgenerator(gen_coro)) + self.assertFalse( + inspect.iscoroutinefunction(unittest.mock.Mock())) + self.assertTrue( + inspect.iscoroutinefunction(unittest.mock.AsyncMock())) self.assertTrue( inspect.iscoroutinefunction(coroutine_function_example)) self.assertTrue( @@ -197,6 +201,10 @@ class TestPredicates(IsTestBase): self.assertTrue(inspect.iscoroutine(coro)) self.assertFalse( + inspect.isgeneratorfunction(unittest.mock.Mock())) + self.assertFalse( + inspect.isgeneratorfunction(unittest.mock.AsyncMock())) + self.assertFalse( inspect.isgeneratorfunction(coroutine_function_example)) self.assertFalse( inspect.isgeneratorfunction( @@ -204,6 +212,12 @@ class TestPredicates(IsTestBase): coroutine_function_example)))) self.assertFalse(inspect.isgenerator(coro)) + self.assertFalse( + inspect.isasyncgenfunction(unittest.mock.Mock())) + self.assertFalse( + inspect.isasyncgenfunction(unittest.mock.AsyncMock())) + self.assertFalse( + inspect.isasyncgenfunction(coroutine_function_example)) self.assertTrue( inspect.isasyncgenfunction(async_generator_function_example)) self.assertTrue( |