Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unitest.mock.create_autospec(async_def) does not create functions valid for inspect.iscoroutinefunction #94924

Closed
graingert opened this issue Jul 17, 2022 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Jul 17, 2022

discovered while creating #94923

Bug report

import unittest.mock
import inspect
import asyncio
import sys

def main():
    async def demo():
        pass
    print(f"{inspect.iscoroutinefunction(unittest.mock.create_autospec(demo))=}")
    print(f"{asyncio.iscoroutinefunction(unittest.mock.create_autospec(demo))=}")


# this prints:
# inspect.iscoroutinefunction(unittest.mock.create_autospec(demo))=False
# asyncio.iscoroutinefunction(unittest.mock.create_autospec(demo))=True

if __name__ == "__main__":
    sys.exit(main())

see also #84753

Linked PRs

@graingert
Copy link
Contributor Author

this will need backporting to 3.10 and 3.11 just like #84753

cjw296 pushed a commit that referenced this issue Jun 9, 2023
…sync_def)` (#94962)

* support inspect.iscoroutinefunction in create_autospec(async_def)

* test create_autospec with inspect.iscoroutine and inspect.iscoroutinefunction

* test when create_autospec functions check their signature
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
@cjw296 cjw296 closed this as completed Mar 18, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Unittest issues Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants