Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9682602

Browse files
Carl Meyerfacebook-github-bot
Carl Meyer
authored andcommitted
restore Mock._spec_asyncs and match upstream
Summary:D42039568 (733b7b3) backported an early version ofpython/cpython#100252,and there were some changes made before that PR was merged upstream.Backport those changes so we match upstream behavior. Most importantly,this restores `_spec_asyncs`, which although a private API does seem to be used.Reviewed By: itamaroDifferential Revision: D42416767fbshipit-source-id:a7e7a21
1 parent6002c4b commit9682602

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

‎Lib/unittest/mock.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
493493
_eat_self=False):
494494
_spec_class=None
495495
_spec_signature=None
496+
_spec_asyncs= []
496497

497498
ifspecisnotNoneandnot_is_list(spec):
498499
ifisinstance(spec,type):
@@ -503,13 +504,20 @@ def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
503504
_spec_as_instance,_eat_self)
504505
_spec_signature=resandres[1]
505506

506-
spec=dir(spec)
507+
spec_list=dir(spec)
508+
509+
forattrinspec_list:
510+
ifiscoroutinefunction(getattr(spec,attr,None)):
511+
_spec_asyncs.append(attr)
512+
513+
spec=spec_list
507514

508515
__dict__=self.__dict__
509516
__dict__['_spec_class']=_spec_class
510517
__dict__['_spec_set']=spec_set
511518
__dict__['_spec_signature']=_spec_signature
512519
__dict__['_mock_methods']=spec
520+
__dict__['_spec_asyncs']=_spec_asyncs
513521

514522
def__get_return_value(self):
515523
ret=self._mock_return_value
@@ -998,8 +1006,7 @@ def _get_child_mock(self, /, **kw):
9981006
For non-callable mocks the callable variant will be used (rather than
9991007
any custom subclass)."""
10001008
_new_name=kw.get("_new_name")
1001-
_spec_val=getattr(self.__dict__["_spec_class"],_new_name,None)
1002-
if_spec_valisnotNoneandasyncio.iscoroutinefunction(_spec_val):
1009+
if_new_nameinself.__dict__['_spec_asyncs']:
10031010
returnAsyncMock(**kw)
10041011

10051012
ifself._mock_sealed:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp