New submission from Tom Most :
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() ->
foo_mock_mock_instance.bar() ->
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() ->
foo_mock_mock_instance.bar() ->
--
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
<https://bugs.python.org/issue41628>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com