[New-bugs-announce] [issue28569] mock.attach_mock should work with return value of patch()

Andrey Fedorov report at bugs.python.org
Mon Oct 31 13:32:14 EDT 2016


New submission from Andrey Fedorov:

The attach_mock in the following code sample fails silently:

    >>> from mock import patch, Mock
    >>> p = patch('requests.get', autospec=True)
    >>> manager = Mock()
    >>> manager.attach_mock(p.start(), 'requests_get')
    >>> import requests
    >>> requests.get('https://google.com')
    <MagicMock name='get()' id='4472381392'>
    >>> manager.mock_calls
    []
    >>> p.stop()
    >>> manager.mock_calls
    []

It seems this would be a useful use-case, especially given that this code would work as-expected if 'requests.get' in the second line were replaced with a path to a class.

----------
components: Library (Lib)
messages: 279812
nosy: Andrey Fedorov, michael.foord
priority: normal
severity: normal
status: open
title: mock.attach_mock should work with return value of patch()
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28569>
_______________________________________


More information about the New-bugs-announce mailing list