Skip to content

Commit 8731cba

Browse files
committed
WIP - fix ignore_warnings to wrap also async functions
1 parent 8955136 commit 8731cba

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Lib/test/support/warnings_helper.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
import warnings
77

8+
import inspect
9+
810

911
def import_deprecated(name):
1012
"""Import *name* while suppressing DeprecationWarning."""
@@ -49,12 +51,20 @@ def ignore_warnings(*, category):
4951
more noisy and tools like 'git blame' less useful.
5052
"""
5153
def decorator(test):
52-
@functools.wraps(test)
53-
def wrapper(self, *args, **kwargs):
54-
with warnings.catch_warnings():
55-
warnings.simplefilter('ignore', category=category)
56-
return test(self, *args, **kwargs)
57-
return wrapper
54+
if inspect.iscoroutinefunction(test):
55+
@functools.wraps(test)
56+
async def async_wrapper(self, *args, **kwargs):
57+
with warnings.catch_warnings():
58+
warnings.simplefilter('ignore', category=category)
59+
return await test(self, *args, **kwargs)
60+
return async_wrapper
61+
else:
62+
@functools.wraps(test)
63+
def wrapper(self, *args, **kwargs):
64+
with warnings.catch_warnings():
65+
warnings.simplefilter('ignore', category=category)
66+
return test(self, *args, **kwargs)
67+
return wrapper
5868
return decorator
5969

6070

0 commit comments

Comments
 (0)