[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

Jeremy Cline report at bugs.python.org
Wed Jun 12 10:00:18 EDT 2019


New submission from Jeremy Cline <jeremy at jcline.org>:

This is related to the new AsyncMock[0] class in Python 3.8b1. A simple reproducer is:

from unittest import mock

mock_obj = mock.MagicMock()
mock_obj.mock_func = mock.MagicMock(spec=lambda x: x)

with mock.patch.object(mock_obj, "mock_func") as nested:
    print(type(nested))


Instead of a MagicMock (the behavior in Python 3.7) in Python 3.8b1 this results in an AsyncMock.

[0]https://github.com/python/cpython/pull/9296

----------
components: Library (Lib)
messages: 345358
nosy: jcline
priority: normal
severity: normal
status: open
title: Mocking a MagicMock with a function spec results in an AsyncMock
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37251>
_______________________________________


More information about the Python-bugs-list mailing list