From 2e0931046dcc200fd6abb2cdfaf57d8b99117c57 Mon Sep 17 00:00:00 2001 From: melanie witt Date: Tue, 23 May 2023 16:10:34 -0700 Subject: gh-85934: Use getattr_static when adding mock spec (#22209) Co-authored-by: Terry Jan Reedy Co-authored-by: Oleg Iarygin --- Lib/unittest/mock.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Lib/unittest') diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 7ca08576065..22f81e55b56 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 -- cgit v1.2.3