[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-28 Thread Andrew Svetlov
Change by Andrew Svetlov : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ __

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-28 Thread miss-islington
miss-islington added the comment: New changeset 436c2b0d67da68465e709a96daac7340af3a5238 by Miss Islington (bot) (Xtreak) in branch 'master': bpo-36996: Handle async functions when mock.patch is used as a decorator (GH-13562) https://github.com/python/cpython/commit/436c2b0d67da68465e709a96d

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-24 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- keywords: +patch pull_requests: +13473 stage: -> patch review pull_request: https://github.com/python/cpython/pull/13562 ___ Python tracker ___

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-21 Thread Lisa Roach
Lisa Roach added the comment: Oops, didn't see your post. Thanks! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-21 Thread Lisa Roach
Lisa Roach added the comment: I quickly threw in Andrew's code to check it and looks like it does fix the problem. I'd be happy to add it in but I'll give @xtreak first dibs. Thanks for finding this :) -- ___ Python tracker

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-21 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks @asvetlov for the explanation. I tried the patch and it works fine for my example with no test failures for mock. I will try to make a PR. Only func(*args, **keywargs) needs to be changed and await requires an async function which I seem to

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-21 Thread Andrew Svetlov
Andrew Svetlov added the comment: Thank you very much for raising the question. @patch(...) creates _patch class instance. For decoration _patch.__call__ is used. def __call__(self, func): if isinstance(func, type): return self.decorate_class(func) return self.

[issue36996] unittest.mock.patch decorator doesn't work with async functions

2019-05-21 Thread Karthikeyan Singaravelan
New submission from Karthikeyan Singaravelan : I came across this while using AsyncMock but it seems to apply to Mock/MagicMock too. When patch decorator is used to wrap an async function to mock sync or async functions it doesn't seem to work. Manually adding patcher or using patch as contex