Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

unittest.mock.patch.dict returns function when applied to coroutines #98086

Closed
Labels
type-bugAn unexpected behavior, bug, or error
@seifertm

Description

@seifertm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp