[issue38857] AsyncMock issue with awaitable return_value/side_effect/wraps
Dima Tisnek
report at bugs.python.org
Sun Feb 16 21:57:16 EST 2020
Dima Tisnek <dimaqq at gmail.com> added the comment:
I think this deserves discussion :)
On one hand, it's a welcome change, on another it's kind of a regression.
Up until 3.8, our tests used to look like this:
---
# code under test
async def foo():
return await bar()
# test
async def helper(value):
return value
async def test_foo():
with patch("bar", return_value=helper(42)):
assert await foo() == 42
---
I feel that the default class `patch()` uses for `new` has crept in too quietly in 3.8.
At the same time, `helper` was only used because there was no `AsyncMock`.
(or at times, a 3rd party library, `asynctest` was used).
So, on one hand, it's a bit of a regression, but on the other, looking ahead, I would really like `unittest.mock` to do the right thing.
Can we have it both ways? If not, what way is a better way?
----------
nosy: +Dima.Tisnek
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38857>
_______________________________________
More information about the Python-bugs-list
mailing list