Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 5 Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,8 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
_spec_signature = None
_spec_asyncs = []

for attr in dir(spec):
if iscoroutinefunction(getattr(spec, attr, None)):
_spec_asyncs.append(attr)
for attr, _ in inspect.getmembers_static(spec, iscoroutinefunction):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about async classmethods? Would those still get recognized as coroutines?

_spec_asyncs.append(attr)

if spec is not None and not _is_list(spec):
if isinstance(spec, type):
Expand Down
14 changes: 14 additions & 0 deletions 14 Lib/unittest/test/testmock/testmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ def test_call(self):
"call_args_list not set")


def test_not_called_descriptor_protocol(self):
import types
class A:
@property
def name(self):
raise NotImplementedError
@types.DynamicClassAttribute
def eggs(self):
raise NotImplementedError

self.assertIsInstance(Mock(spec=A), A)
self.assertIsInstance(Mock(spec=A()), A)


def test_call_args_comparison(self):
mock = Mock()
mock()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`unittest.mock` triggers dynamic lookup via the descriptor
protocol. Patch by Weipeng Hong.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.