summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r--Lib/test/support/__init__.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index ff7db991..39dea88 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -3241,3 +3241,31 @@ def infinite_recursion(max_depth=75):
yield
finally:
sys.setrecursionlimit(original_depth)
+
+def ignore_deprecations_from(module: str, *, like: str) -> object:
+ token = object()
+ warnings.filterwarnings(
+ "ignore",
+ category=DeprecationWarning,
+ module=module,
+ message=like + fr"(?#support{id(token)})",
+ )
+ return token
+
+def clear_ignored_deprecations(*tokens: object) -> None:
+ if not tokens:
+ raise ValueError("Provide token or tokens returned by ignore_deprecations_from")
+
+ new_filters = []
+ for action, message, category, module, lineno in warnings.filters:
+ if action == "ignore" and category is DeprecationWarning:
+ if isinstance(message, re.Pattern):
+ message = message.pattern
+ if tokens:
+ endswith = tuple(rf"(?#support{id(token)})" for token in tokens)
+ if message.endswith(endswith):
+ continue
+ new_filters.append((action, message, category, module, lineno))
+ if warnings.filters != new_filters:
+ warnings.filters[:] = new_filters
+ warnings._filters_mutated()