[New-bugs-announce] [issue41628] All unittest.mock autospec-generated methods are coroutine functions
Tom Most
report at bugs.python.org
Mon Aug 24 19:31:52 EDT 2020
New submission from Tom Most <bugs.python.org at freecog.net>:
Given a class:
class Foo:
def bar(self):
pass
And an autospec'd mock of it:
foo_mock = mock.create_autospec(spec=Foo)
The result of `asyncio.iscoroutinefunction()` differs:
asyncio.iscoroutinefunction(Foo.bar) # -> False
asyncio.iscoroutinefunction(foo_mock.bar) # -> True
This behavior is the same on Python 3.7 and 3.8.
I've attached a demonstration script, repro4.py. Here is the output on Python 3.7.9:
$ python3.7 repro4.py
baz is a coroutine function? False
Foo.bar is a coroutine function? False
foo_instance.bar is a coroutine function? False
baz_mock is a coroutine function? False
foo_mock.bar is a coroutine function? True
foo_mock_instance.bar is a coroutine function? True
foo_mock_mock.bar is a coroutine function? False
foo_mock_mock_instance.bar is a coroutine function? False
foo_mock_instance.bar() -> <MagicMock name='mock().bar()' id='140602586963280'>
foo_mock_mock_instance.bar() -> <Mock name='mock().bar()' id='140602587010192'>
And on Python 3.8.2:
python3.8 repro4.py
baz is a coroutine function? False
Foo.bar is a coroutine function? False
foo_instance.bar is a coroutine function? False
baz_mock is a coroutine function? False
foo_mock.bar is a coroutine function? True
foo_mock_instance.bar is a coroutine function? True
foo_mock_mock.bar is a coroutine function? True
foo_mock_mock_instance.bar is a coroutine function? False
foo_mock_instance.bar() -> <MagicMock name='mock().bar()' id='139847100001728'>
foo_mock_mock_instance.bar() -> <Mock name='mock().bar()' id='139847100037968'>
----------
components: Library (Lib)
files: repro4.py
messages: 375862
nosy: twm
priority: normal
severity: normal
status: open
title: All unittest.mock autospec-generated methods are coroutine functions
type: behavior
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file49425/repro4.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41628>
_______________________________________
More information about the New-bugs-announce
mailing list