Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
unittest.mock.patch.dict returns a synchronous function when applied to coroutines. Contrary to that,unittest.mock.patch returns coroutines when applied to coroutines (see#81177).
My expectation is thatpatch andpatch.dict behave the same when applied to coroutines. I expect the following code to printTrue andTrue, but it printsTrue andFalse for CPython>=3.8:
import inspectfrom unittest.mock import Mock, patch@patch("binascii.b64encode")async def patch_coro(): ...@patch.dict("sys.modules", test_module=Mock())async def patch_dict_coro(): ...print(inspect.iscoroutinefunction(patch_coro))print(inspect.iscoroutinefunction(patch_dict_coro))Your environment
- CPython versions tested on: 3.7, 3.8, 3.9, 3.10, 3.11-rc2
- Operating system and architecture: Linux x86_64
CPython v3.7 is not affected by this issue, because support for coroutines was added tomock.patch in v3.8 (see#81177). The supplied example printsFalse andFalse.