Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +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)):
for attr, value in inspect.getmembers_static(spec):
if iscoroutinefunction(value):
_spec_asyncs.append(attr)

if spec is not None and not _is_list(spec):
Expand Down
14 changes: 14 additions & 0 deletions 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.