diff options
author | melanie witt <melwittt@gmail.com> | 2023-05-23 23:10:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-23 23:10:34 (GMT) |
commit | 2e0931046dcc200fd6abb2cdfaf57d8b99117c57 (patch) | |
tree | ebb46d171eacd829f6ec537077a812676393d4ca /Lib/unittest | |
parent | 6b1510cf11c16c8e4381810c15ceeda6f89e79f4 (diff) | |
download | cpython-2e0931046dcc200fd6abb2cdfaf57d8b99117c57.zip cpython-2e0931046dcc200fd6abb2cdfaf57d8b99117c57.tar.gz cpython-2e0931046dcc200fd6abb2cdfaf57d8b99117c57.tar.bz2 |
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>
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/mock.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 7ca0857..22f81e5 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -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 |