This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anfedorov
Recipients anfedorov, michael.foord, shmed
Date 2016-11-12.03:22:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAH3wspm8YpOtgvAU=Bw2nqL7j4ZiUzN-kXNCkcP5ZL9W5EwSzg@mail.gmail.com>
In-reply-to <CAH3wspm=r-qaJA9UFdGPnecRsqBNjSBeLt58AgKrCQAMTnw4UQ@mail.gmail.com>
Content
To clarify, this is how I would expect these two functions to work together
"out of the box"

patches = { 'requests_get': 'requests.get', ... }

root_mock = mock.Mock()
for name, path in patches.items():
    m = mock.patch(path, auto_spec=True)
    root_mock.attach_mock(m, name)

This works when `path` is referring to a class, and it would be great if it
also worked with functions like `requests.get`, as well.

On Fri, Nov 11, 2016 at 5:16 PM, Andrey Fedorov <me@anfedorov.com> wrote:

> There's some vagueness on how this is implemented, but I would prefer
> manager.attach_mock to also work with whatever the return value of patch()
> is.
>
> On Fri, Nov 11, 2016 at 12:08 PM, Syed Suhail Ahmed <
> report@bugs.python.org> wrote:
>
>>
>> Syed Suhail Ahmed added the comment:
>>
>> So from what I have understood, manager.attach_mock must raise an
>> Exception when it is called with a wrong attribute, since the patch is
>> called with autospec=True and you cannot call a mock with non existing
>> attributes.Is that correct?
>>
>> ----------
>>
>> _______________________________________
>> Python tracker <report@bugs.python.org>
>> <http://bugs.python.org/issue28569>
>> _______________________________________
>>
>
>
History
Date User Action Args
2016-11-12 03:22:54anfedorovsetrecipients: + anfedorov, michael.foord, shmed
2016-11-12 03:22:53anfedorovlinkissue28569 messages
2016-11-12 03:22:52anfedorovcreate