diff options
author | Mehdi ABAAKOUK <sileht@sileht.net> | 2022-06-30 17:08:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-30 17:08:38 (GMT) |
commit | 4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc (patch) | |
tree | 004df1f1a95ed6113b55ab0f92d3e66b405fd424 /Lib/test/test_inspect.py | |
parent | 639e35108bc8b2b880225862d3571277ad57648b (diff) | |
download | cpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.zip cpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.tar.gz cpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.tar.bz2 |
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (#94050)
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>
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index ae18427..be9f29e 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -202,6 +202,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( @@ -211,6 +215,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( @@ -218,6 +226,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( |