gh-85934: Use getattr_static when adding mock spec (#22209)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
This commit is contained in:
melanie witt 2023-05-23 16:10:34 -07:00 committed by GitHub
parent 6b1510cf11
commit 2e0931046d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -526,7 +526,13 @@ class NonCallableMock(Base):
spec_list = dir(spec)
for attr in spec_list:
if iscoroutinefunction(getattr(spec, attr, None)):
static_attr = inspect.getattr_static(spec, attr, None)
unwrapped_attr = static_attr
try:
unwrapped_attr = inspect.unwrap(unwrapped_attr)
except ValueError:
pass
if iscoroutinefunction(unwrapped_attr):
_spec_asyncs.append(attr)
spec = spec_list