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 <[email protected]>
<http://bugs.python.org/issue28569>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com