New submission from Tom Most <bugs.python....@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 <rep...@bugs.python.org> <https://bugs.python.org/issue41628> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com